Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1770
swapping content with outlook bar not working
posted

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.

ContentSwapExample.zip
Parents
  • 12875
    posted

    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.

     

Reply Children