Binding pivotitem content in WP8.1 - windows-phone-8.1

In my mainpage.xaml I have a pivot control:
<Pivot x:Name="Pivot"
ItemsSource="{Binding PivotItems}"
ItemTemplate="{StaticResource PivotItemTemplate}">
</Pivot>
which binds it's items to a PivotsItems property on my viewmodel. The pivotitems are shown correctly but i'm not able to bind the content of the pivotitem.
My datatemplate looks like:
<DataTemplate x:Key="PivotItemTemplate">
<PivotItem>
<TextBlock Text="Test"></TextBlock>
</PivotItem>
</DataTemplate>
But no content is shown in any pivotitem.
What I wan't to do is to bind the pivotitems (which works) but show a seperate filter for each pivotitem. In this example I just want to show a TextBlock in each pivotitem.
SOLVED:
I defined the itemtemplate on the pivot control in the page, while i had to add it when populating the list in the vm:
PivotItems.Add(new PivotItem { Header = item.Key, ContentTemplate = App.Current.Resources["PivotItemTemplate"] as DataTemplate });

Pivot automatically Wraps it's items into PivotItems (like you don't add ListViewItem to a ListViews ItemsTemplate). Just put your content into the DataTemplate.
<DataTemplate x:Key="PivotItemTemplate">
<TextBlock Text="Test"></TextBlock>
</DataTemplate>
The header defaults to the DataContext of the PivotItem (so your list item). If you want it to display a certain property, you have to set the HeaderTemplate too:
<DataTemplate>
<TextBlock Text="{Binding MyProperty}" />
</DataTemplate>
If you just keep it as a TextBlock with no further properties, the default style gets applied perfectly.

Related

Create Tab Items and Tab Content dynamically using Orchestra/Catel

I am attempting to create a tabbed interface using Orchestra/Catel. I load the tabs definitions into a TabInfo class. Those work fine - a tabbed interface is created with the correct tab descriptions. In the content for each tab, I want to create a list of buttons - again loaded into a ButtonInfo class. When a tab is selected, the SelectedTab property is used to select the correct list of buttons (ShowButtons).
I have traced the program and when I click on a tab, the correct collection of buttons is in ShowButtons, but nothing shows up in the tab content. I did get this to work in a normal MVVM program, but without the tabs. I used a listview to show my tabs and an ItemsControl to show the buttons.
Belows is my XAML code for the tabs and my SelectedTab logic for pulling the buttons.```
<Grid>
<orccontrols:TabControl LoadTabItems="LazyLoading" ItemsSource="{Binding TabInfo}" SelectedItem="{Binding SelectedTab}">
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding TabDesc}"/>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding ShowButtons}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical" IsItemsHost="True"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding ButtonDesc}"
MinWidth="150"
Height="30"
FontSize="12"
FontWeight="Bold"
Margin="0,15,25,10"
Padding="5,1">
<Button.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding OracleJob}" Value="0">
<Setter Property="Button.Background" Value="DarkSalmon" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</TabControl.ContentTemplate>
</orccontrols:TabControl>
</Grid>
And the code for populating ShowButtons:
public void OnSelectedTabChanged()
{
int _selectTab = SelectedTab.TabKey;
var _showButtons = ButtonInfo.Where(i => i.ButtonTab == _selectTab);
ObservableCollection<ButtonRecord> _btn = new ObservableCollection<ButtonRecord>(_showButtons);
ShowButtons = _btn;
}
Any help is greatly appreciated. I am a beginner with Orchestra/Catel, so I am probably missing the best way to do this.
I recommend to split up the issue from Orchestra / Catel. Orchestra allows you to provide a view as shell, but this view can live on it's own (the only thing Orchestra does is place it inside the correct location inside the shell). By making this problem unrelated to Orchestra, it makes it a bit easier for us to solve.
Next up, I recommend looking into the Catel docs. There is a full example on how to show a shell with tabs with closable tab buttons, see https://docs.catelproject.com/vnext/tips-tricks/mvvm/using-tabbed-interface-with-mvvm/

Items being reordered in LongListSelector

In my WP8 app, I'm using LongListSelector to display data items. Grouping works, jump list works.
I have the usual master/detail scenario here - click on item in the list, new page shows up with more information.
The problem is with navigating back to the page with LongListSelector. The list is basically messed up - items are randomly reordered, even between groups. Clicking on an item works properly - ShowItemInfo receives view model for the item the user clicked on.
Previously I was using ListBox, which too suffered from this issue. But I could disable virtualization by using default StackPanel as items panel. I don't know how to disable virtualization on LongListSelector (I don't want to, but the bug is horrible).
View model is simple. I'm using Caliburn.Micro, its conventions and BindableCollection for list of groups. I populate the list just once with AddRange method.
When the page is navigated back to, I'm not doing anything - and I even can't since I use MVVM and Caliburn.Micro. The items are loaded into list in OnInitialize callback, which is invoked only once during lifetime of view model.
The XAML for view is this:
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.Resources>
<phone:JumpListItemBackgroundConverter x:Key="BackgroundConverter"/>
<phone:JumpListItemForegroundConverter x:Key="ForegroundConverter"/>
<Style x:Key="ListJumpListStyle" TargetType="phone:LongListSelector">
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<Border Background="{Binding Converter={StaticResource BackgroundConverter}}"
HorizontalAlignment="Stretch">
<TextBlock Text="{Binding GroupTitle}"
Foreground="{Binding Converter={StaticResource ForegroundConverter}}" />
</Border>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<phone:LongListSelector x:Name="Items" LayoutMode="List" IsGroupingEnabled="True"
JumpListStyle="{StaticResource ListJumpListStyle}">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<Grid cal:Bind.Model="{Binding}"
cal:Message.Attach="[Event Tap] = [ShowItemInfo($dataContext)]"
Background="Transparent">
<TextBlock x:Name="ItemText" Style="{StaticResource PhoneTextTitle2Style}" />
</Grid>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
<phone:LongListSelector.GroupHeaderTemplate>
<DataTemplate>
<Border>
<TextBlock Text="{Binding GroupTitle}" />
</Border>
</DataTemplate>
</phone:LongListSelector.GroupHeaderTemplate>
</phone:LongListSelector>
</Grid>
I've narrowed down the issue to the data template, more specifically the attached property Bind.Model, which allows Caliburn.Micro to bind view model to view:
<DataTemplate>
<Grid cal:Bind.Model="{Binding}"
cal:Message.Attach="[Event Tap] = [ShowItemInfo($dataContext)]"
Background="Transparent">
<TextBlock x:Name="ItemText" Style="{StaticResource PhoneTextTitle2Style}" />
</Grid>
</DataTemplate>
When this view is changed to use explicit bindings instead conventions (and Bind.Model attached property is removed), LongListSelector works like a charm.
I believe there has to be a bug within Caliburn.Micro, which causes this issue. Initially, I thought the bug was in the 1.5.2 version, which I'm using (unfortunately I have to), and that it was fixed in new 2.x versions. However, that is not true, the bug is still manifesting in latest stable version 2.0.2.
I was using this technique in WPF without any problems. I've also tried running the app in emulators for WP8.0 and WP8.1, but the behavior is the same.
If anybody finds out, what causes this bug (or new version of Caliburn.Micro fixes it), feel free to edit answer or post a comment. I would be happy to use conventions in data templates again.
My mistake: for data templates, Bind.ModelWithoutContext should be used. Even documentation explicitly says so:
Bind.ModelWithoutContext - View-First - Set’s the Action.Target to the specified instance. Applies conventions to the view. (Use inside
of DataTemplate.)
With Bind.ModelWithoutContext LongListSelector works properly as it should (with conventions in item template).

Remove commandbar ability to expand WP 8.1

I want to remove the ability to expand the command bar. (no dots)
Is this possible?
AFAIK it's not possible to remove the ellipsis (those three dots) from application bar.
If you have no Secondary commands then ellipsis will just show labels of your app bar buttons. Taking a look at ClosedDisplayMode you have only two values: minimal and compact - which means that you cannot have app bar opened with labels without ellipsis.
Other way may be to build your own control which will immitate application bar - then you can put there what you want.
As Romasz Said it's not possible to remove the three dots. But you can create a template smiler to application bar, something like that :
<Grid x:Name="LayoutRoot" >
<Grid VerticalAlignment="Bottom" Background="#FF1F1F1F" >
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal" >
<AppBarButton x:Name="test1" Icon="Play"/>
<AppBarButton x:Name="test2" Icon="ReShare"/>
</StackPanel>
</Grid>
</Grid>
And this will give you :

while progress bar is running how to disable other controls of the page in WPF

How can i have a loading/progress bar on the page while it is taking time to call a service,also until the call and response is not complete the controls should not be accessible
Try this way, Create a empty grid behind the Progress Bar that cover the whole screen and set its opacity of say 0.5 so that background is paritially visible.
<Grid Grid.Row="0" x:Name="GrdProgressBar" Background="Transparent" >
<Grid Background="White" Opacity="0.5"></Grid>
<StackPanel VerticalAlignment="Center">
<ProgressBar IsIndeterminate="True" Foreground="Green" Margin="0,5,0,0" ></ProgressBar>
<TextBlock Text="loading.." FontSize="20" FontStyle="Italic" Foreground="Black" HorizontalAlignment="Center" ></TextBlock>
</StackPanel>
</Grid>
What you have to done set the visibility of `GrdProgressBara as you do with ProgessBar.
Hope it help you :)
Another way is to use a property IsLoading that is true while the service call is in progress and false after the call finished. Then you can use a converter and bind your IsEnabled property of your controls to the inverse IsLoading value. So while your service call is running, all controls are disabled and when the call finishes, the control will be reenabled. You just need to set the IsLoading property and bind within XAML. No additional code needed.

Panorama-control don't remember selected panorama item when navigating

I'm using a panorama control in my wp8 app that consists of 4 panorama-items. These items are all i separate files. The content within the items are bound to viewmodels, (using MVVM Cross).
The problem is when I navigate from a panorama-item to a new page and go back, the panorama control shows the first panorama-item (it kinda resets).
I've tried to override OnNavigatedTousing the selectedIndexon the panorama control, but it only returns -1.
The xaml class containing the panorama-control:
<Grid x:Name="LayoutRoot" Background="Transparent">
<!--Panorama Control-->
<!--Cannot bind directly to background with ImageBrush, using converter instead-->
<controls:Panorama x:Name="panorama"
Background="{Binding Home.WindowsBackgroundUrl, Converter={StaticResource ImageBrushConverter}}">
<controls:Panorama.Title>
<StackPanel Orientation="Vertical" Margin="0,60,0,0">
<Image x:Name="Icon" Source="/Images/PanoramaLogo.png" />
</StackPanel>
</controls:Panorama.Title>
<!--Panorama items-->
<ScrollViewer>
<local:InterestView x:Name="Interest" Margin="0,-20,0,0" />
</ScrollViewer>
<ScrollViewer>
<local:CustomerCategoryPanoramaItem x:Name="Customer" Margin="0,-20,0,0"/>
</ScrollViewer>
<ScrollViewer>
<local:MapListView x:Name="MapList" Margin="0,-20,0,0"/>
</ScrollViewer>
<ScrollViewer>
<local:ContactMeView Margin="0,-20,0,0"/>
</ScrollViewer>
</controls:Panorama>
</Grid>
Thanks for any help
If you are persisting your screen in view stack than it panorama-control will take care of that other-vice we have to persist selected panorama while we are navigating forward and when we come back to Panorama control. For that we has to set its DefaultItem property .
Panorama numbers its view starting from 0, Like for if we have three panorama Items than it will give 0 to first, 1 to second and 2 to third.
Example :
PanoramaControl.DefaultItem = PanoramaControl.Items[0 to 2];