Hello. I swap the content out using the <ContentControl> tag based on something click in the XamOutlookBar control. When I click on a particular OutlookBarGroup a command is sent to the view model to swap out the content in a certain part of the main window as per the code block below.
<ContentControl Content="{Binding CurrentPageViewModel}" Grid.Column="1" />
private void OnBarGroupClick(object barGroupKey){ if (barGroupKey.ToString() == "LogsBarGroupKey"){CurrentPageViewModel = _logsViewModel;}
So when clicking on bar group everything works fine. One of the bar groups contains a tree as so:
<TreeViewItem Header="Station Reporting" Name="StationReportingTree"> <TreeViewItem Name="VariousReportsItem" Header="REPORTS"/> </TreeViewItem>
When I click on the VariousReportsItem in the tree a command is sent to swap out the content since there will be various reports.
private void OnReportSelection(object treeViewItemName){ if (treeViewItemName != null){ if (treeViewItemName.ToString() == "VariousReportsItem"){ CurrentPageViewModel = _variousReportsViewModel;}} }
So I can see the OnReportsSelection method being reached and the CurrentPageViewModel = _variousReportsViewModel statement gets executed but the content does not get swapped out and I have no idea why.
I've included a sample project with this issue. Thanks.
Hi,
I spent some time with your sample and the OnBarGroupChangeCommand is being hit anytime you use the MouseLeftButtonUp inside the TreeView as well as on the ReportsBarGroup. So your CurrentPageViewModel is be set to the _variousReportsViewModel and then replaced with the _reportsViewModel.
The solution might be to use a different event trigger for the TreeView or create a separate command for the ReportsBarGroup and keep track of whether you have just hit the treeview. One other solution might be to look into MVVM Light where you can pass event args to the command.
Please let me know if you have any questions.
The problem turned out to be that when an TreeViewItem was clicked the event associated with that click would fire and the ContentControl would be set BUT also right after the event when a bar group was clicked also fired re-setting the view.
As far as I understand your answer I'm doing everything you've suggested already. The problem is that the content does not get swapped when someone presses something in the tree view.
Here is an example of how this could possibly be resolved http://www.japf.fr/2009/03/thinking-with-mvvm-data-templates-contentcontrol/ . It involves binding the view models to the ItemsSource of the ListBox.
<ListBox Name="LogsListBox" ItemsSource="{Binding LogsUserControls}" SelectedIndex="0"> </ListBox>
Does OutlookBarGroup does not have a ItemsSource property. Do you see some other way this can be done using this type of binding?