Multiple Windows

Dec 15, 2010 at 4:20 AM

Hello Rishi,

How can we have multiple windows opened at a time and displayed as tab pages, that means having a Tabbed MDI and when for example a user tries no open a page that has already been opened we should be able to activate it rather than opening a new page.

For example in HR application if I open an employee record with PF no 10100000 for editing. Then if I try to open the same form the Navigation manager should just activate the previously opened page so that I can have only one page with same details at once.

A tabbed shell like in LightSwitch would be very nice Rishi.

Thanks.

Coordinator
Dec 16, 2010 at 10:24 AM
Edited Dec 16, 2010 at 10:41 AM

Hi, making a tab-like interface using nRoute isn't so hard - and to prove the point I've made a simple tabbed-navigation app (download from http://cid-587cbdf035b4a11d.office.live.com/self.aspx/.Public/TabsNavigation.zip). Basically to enable tabbed-navigation handling, I created an adapter for tabs control. The adapter's logic is quite simple:

    public class TabControlNavigationAdapter : NavigationAdapterBehaviorBase<TabControl>
    {
        public override object Content
        {
            get 
            {
                if (this.AssociatedObject.Items.Count > 0)
                {
                    foreach (TabItem _tabItem in this.AssociatedObject.Items)
                    {
                        if (_tabItem.IsSelected)
                        {
                            return _tabItem.Content;
                        }
                    }
                }
                return null;
            }
        }

        protected override void OnSetNavigationContent(object content)
        {
            var _tabItem = new TabItem();
            _tabItem.Content = content;
            _tabItem.Header = Navigation.GetTitle(content as DependencyObject) ?? "Untitled";

            this.AssociatedObject.Items.Add(_tabItem);
            _tabItem.IsSelected = true;
        }
    }

Above I'm handling two methods, one to return the current displayed content, and another to set the content in response to a navigation - which in our case simply creates a new tab. Now, it is possible to have much more richer logic in place; specifically for what you wanted, consider overriding some of the navigation specific methods (like OnProcessResponse) that can give you more info about the url, request, response etc. 

Secondly, to use the adapter, I just dragged drop it onto the tab control. I also added another behavior that makes it "default" navigation handler for the application, and the xaml with the two behaviors looks like:

 

<sdk:TabControl x:Name="tabControl" Margin="12,135,12,12" BorderThickness="0"> 
    <i:Interaction.Behaviors>
    	<TabsNavigation_Behaviors:TabControlNavigationAdapter/>
    	<n:NavigationHandlerBehavior IsDefaultHandler="True"/>
    </i:Interaction.Behaviors> 
</sdk:TabControl>

 

Hope this helps,
Rishi 

Coordinator
Dec 16, 2010 at 10:38 AM

Oh I forgot to mention - if you want a robust MDI type app framework, then look into http://chronoswpf.codeplex.com/ - it is build upon nRoute. Soon a Silverlight version will be forthcoming too.

Cheers,
Rishi