Hi All,
I'm new to WPF and would require help in fixing an issue.
Scenario: We have tab control, say Configuration, Admin etc., based UI for administrator use. In one of the tab control (Configuration), we have Menu Control which is binded with List of Task and indeed each menu item (currently we have 3 items say Task1, Task2 and Task 3) is binded to a particular view/view model. Similarly we have different view on different tab controls not necessary contains menu control, may have treeview control.
Issue: When I select a menu item, lets say Task3, then select the different tab control say Admin, select different item from treeview and then come back to the configuration tab. I found that the menu item selected is not Task3 but Task1 but the view displayed is that which is binded with Task3.
Requirement: I want to display the last selected menu item when the same tab control is selected.
Following is my user control code.
<Style TargetType="{x:Type MenuItem}" x:Key="MenuItemStyle"><Setter Property="Header" Value="{Binding Path=Name}" /><Setter Property="Command" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.MenuItemChangedCommand}"/><Setter Property="CommandParameter" Value="{Binding Path=Name}" /><Style.Triggers><MultiTrigger><MultiTrigger.Conditions><Condition Property="IsEnabled" Value="True" /><Condition Property="IsFocused" Value="True" /></MultiTrigger.Conditions><Setter Property="Background" Value="LightGray" /><Setter Property="FontSize" Value="16"/></MultiTrigger></Style.Triggers></Style><Grid><Grid.ColumnDefinitions><ColumnDefinition Width="170"/><ColumnDefinition /></Grid.ColumnDefinitions><Border Grid.Column="0" Margin="5" BorderThickness="1" BorderBrush="Black" CornerRadius="2"><Menu Name="menu" Background="White" ItemsSource="{Binding MenuItemCollection}" ItemContainerStyle="{StaticResource MenuItemStyle}"><Menu.ItemsPanel><ItemsPanelTemplate><VirtualizingStackPanel Orientation="Vertical" /></ItemsPanelTemplate></Menu.ItemsPanel></Menu></Border><Border Grid.Column="1" Margin="5" BorderBrush="Black" CornerRadius="2" BorderThickness="1" Background="White"><Presentation:CustomContentPresenter Content="{Binding SelectedTask, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="2" ComponentContract="ITaskView"></Presentation:CustomContentPresenter></Border></Grid>
Question 1: Is there any gap in synchronization between my Menu Item and View displayed for that menu item?
Question 2: Is that the Menu Control behavior to display default first item as selected, since Menu Control don't have selecteditem property?
Question 3: Is the decision on using Menu control is correct or I should have use different control?
I'll appreciate your help.
Regards.
Somit