0
votes

In my mainwindow i have a tab control, i need to notify different modules that different tabs has been activated or closed. The tabcontrols SelectedItem is bound to ActiveView in my viewmodel

<TabControl Padding="0"  SelectedItem="{Binding ActiveView}"
                    x:Name="MainViewTab" prism:RegionManager.RegionName="{x:Static inf:RegionNames.MainRegion}"
                    VerticalAlignment="Stretch"
                    ItemContainerStyle="{DynamicResource TabHeaderStyle}" 
                    AutomationProperties.AutomationId="MainViewDeatilTab"        
 />

In the region Mainregion i load different views

 UriQuery parameters = new UriQuery();
            parameters.Add("OBJECTID", item.ObjectId.ToString());
            regionManager.RequestNavigate(RegionNames.MainRegion,
                                            new Uri("AIT.Modules.SiteEditor.Views.SiteEditor" + parameters.ToString(), UriKind.Relative),
                                            NavigationCompleted);

The selecteditem is bound to property ActiveView and in the property i need to raise an event that contains OBJECTID as a paramenter.

My problem is that the tabcontrols SelectedItem fires before the view has a chance to load the OBJECTID parameter, which i load in Prism OnNavigatedTo . Anyone has an example on how you manage tabcontrols open and close events so other modules can be notified about current views?

1

1 Answers

2
votes

If you're not detesting code-behind within your mainwindow, you may subscribe the public Navigated event of the region's navigation service one can access via the NavigationService-property of IRegion. The corresponding event handler gets the NavigationContext of the navigation request and thus the URI. As an compromise you could just delegate the event handling from your mainwindow-code-behind to your viewmodel. This is at least one approach I once used.

To avoid the code-behind, you could write a attached property for the RegionManager that does the connection between the event and your viewmodel for you.

Hope this helps.