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/
Related
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).
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.
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 :
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];
I am new to WP development and trying to get hands-on.
If you look at wallet pin screen, focus is automatically set to textbox so that user can start typing and also the keyboard does not hides/overlaps done & cancel button.
Also, If you hit back key, those buttons remain at bottom as shown below.
I am also trying to have same kind of UI. However, In my case
I am not able to set focus to textbox as soon as page is loaded. I
can't get .Focus() method of textbox in OnNavigatedTo event. Where
should i do this ?
When i manually tap textbox to enter a value, the keyboard overlaps
my stackpanel containing 'save' & 'cancel' button as shown below. I
don't want this to happen. Instead the screen should look like as
shown in 2nd image.
Below is the XAML code i tried.
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<StackPanel>
<TextBlock Name="txtLimit" TextWrapping="Wrap" Text="Enter the value" Style="{StaticResource PhoneTextSubtleStyle}"/>
<TextBox AcceptsReturn="True" InputScope="Number" />
</StackPanel>
<StackPanel VerticalAlignment="Bottom" HorizontalAlignment="Center" Orientation="Horizontal" >
<Button Content="save" Width="200" />
<Button Content="cancel" Width="200"/>
</StackPanel>
</Grid>
For setting the focus for first time navigation you apparently have to set this in the Loaded event handler.
For back navigation (from when you application is switched away), the one in OnNavigatedTo will fire as you'd expect.
// Constructor
public MainPage()
{
InitializeComponent();
this.Loaded += (sender, args) => this.textBox.Focus();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
this.textBox.Focus();
}
However you will need to add your buttons to the ApplicationBar to show below the on-screen keyboard.
However the SDK doesn't allow use of rectangular buttons in the application bar, only icon buttons.
In the OnNavigatedTo method, can you try to use the Dispatcher like this :
Dispatcher.BeginInvoke(()=>{
this.textBox.Focus();
});
And, as pointed out, you can NOT have rectangular buttons in the appBar but you can use standard one (like the linked in button for example).