I started with the MVVM Wpf Ribbon sample released by Microsoft.
This is my style for RibbonTab notice IsSelected is bound to IsSelected in The view model.
I started with the MVVM Wpf Ribbon sample released by Microsoft.
This is my style for RibbonTab notice IsSelected is bound to IsSelected in The view model.
<!-- RibbonTab -->
<Style TargetType="{x:Type ribbon:RibbonTab}">
<Setter Property="ContextualTabGroupHeader" Value="{Binding ContextualTabGroupHeader}" />
<Setter Property="Header" Value="{Binding Header}" />
<Setter Property="ItemsSource" Value="{Binding GroupDataCollection}" />
<Setter Property="IsSelected" Value="{Binding IsSelected}" />
</Style>
This is in my view model code for the TabData.
public bool IsSelected
{
get
{
return _isSelected;
}
set
{
if (_isSelected != value)
{
_isSelected = value;
OnPropertyChanged(new PropertyChangedEventArgs("IsSelected"));
}
}
}
private bool _isSelected;
In the constructor for the TabViewModel I take a parameter for the ViewModel of the content. And a public property to a bind to it.
public TabData(ISelectedContentTab content): this(content.DisplayName)
{
_selectedContent = content;
}
private ISelectedContentTab _selectedContent;
public ISelectedContentTab SelectedContent
{
get
{
return _selectedContent;
}
}
Then I used an ItemsControl to display the selected content in my xaml
<ItemsControl Grid.Row="1" VerticalContentAlignment="Stretch" VerticalAlignment="Stretch"
ItemsSource="{Binding ElementName=ribbon,Path=SelectedItems}"
ItemTemplate="{StaticResource ContentControlTemplate}" />
And the ContentControlTemplate I have is
<DataTemplate x:Key="ContentControlTemplate">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ContentControl Grid.Row="0" VerticalAlignment="Stretch" Height="Auto" VerticalContentAlignment="Stretch" Content="{Binding SelectedContent}" />
</Grid>
</DataTemplate>
Also make sure you have a datatemplate pointing your content to a view
Hope this helps some folks out!
