How to do MVVM with WPF Navigation Pane
Categories: DotNetBar for WPF, How To
For MVVM usage scenarios you bind the NavigationPane.ItemSource to the list of your custom view objects. Here is how to create and bind items properly:
<dc:NavigationPane DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" ItemsSource="{Binding Path=PaneItems}" LargeItemsCount="2"> <dc:NavigationPane.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Path=DisplayName}" /> </DataTemplate> </dc:NavigationPane.ItemTemplate> <dc:NavigationPane.ItemContainerStyle> <Style TargetType="{x:Type dc:PaneItem}"> <Setter Property="ImageSource" Value="{Binding Path=DisplayImage}" /> </Style> </dc:NavigationPane.ItemContainerStyle> </dc:NavigationPane>
Notice that we created new ItemTemplate and also notice how Image is set by creating ItemContainerStyle.
Related posts:
Leave a Reply!