Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New Window in a TabItem?

Is it possible to open another Window in a TabControl's TabItem?

The reason I want to do this is that if I have 5 TabItems in my TabControl, the one Window file I'm coding all these TabItems and their associated actions will get very large. So it would be nice if it was possible to to give each TabItem its own Window file.

Or how do you solve the problem where theWindow file controlling the TabControl gets too large?

like image 291
Poku Avatar asked Dec 18 '09 07:12

Poku


2 Answers

<Window ...
     xmlns:local="clr-namespace:MyNamespace"
     >
     <TabControl>
          <TabItem Header="FirstTab">
               <local:MyFirstTabUserControl/>  
          </TabItem>
          <TabItem Header="SecondTab">
               <local:MySecondTabUserControl/>  
          </TabItem>
          <TabItem Header="ThirdTab">
               <local:MyThirdTabUserControl/>  
          </TabItem>
     </TabControl>
</Window>

Your each TabUserControl is actually simple UserControl, since TabItem can host any control as its own child.

like image 62
Akash Kava Avatar answered Oct 20 '22 23:10

Akash Kava


You have several choices:

  • add one or more resource dictionaries to your app that contain resources with templates and styles for the various views you host in your tabs. This approach works well if you just need to maintain separation of the visual trees only.
  • create user controls for each view (with own XAML and class file) and use one instance for each different view in the tabs. This approach allows you to encapsulated specific business logic and the corresponding visual tree together.
  • generate some of the UI from code. This one has no advantages, except t makes you XAML smaller. And is your .cs files become too big, you can always split them in multiple code files and use partial classes. (just had to throw in this one for completeness :-))
like image 43
Franci Penov Avatar answered Oct 20 '22 23:10

Franci Penov