I have 2 tabs, when a button is clicked, tab2 is set to be collapsed. but the content of tab2 is still shown after the click.
Is a easier why to let the selected tab to be tab1 if tab2's visibility is set to collapsed.
Thanks,
Joan
Hi Joan,
The area where the content is displayed is treated differently than where the tab headers are. This means that setting the visibility of the tab item is only going to effect the tab header, not the content area. You have three options that I'm aware of that will hide the content area as well.
1.) The first option is to use what you suggested and switch the selected tab to tab1 when tab2 is collapsed.
2.) Option two is to bind tab2's content to tab2's visibility so when the tab is collapsed, the content will collapse as well.
<igWindows:TabItemEx Header="Tab 2" x:Name="tab2"> <Grid Visibility="{Binding ElementName=tab2, Path=Visibility}"> <!-- Tab 2 content goes in here. --> </Grid> </igWindows:TabItemEx>
3.) Remove tab2 from the tab control when you want to "collapse" it. Place it back in the tab control when you want it visible.
I personally think option two is easiest as it can all be done in XAML without adding anything extra in code-behind.
Let me know if you have any questions on this.
yes. that works. but when I tired to use style to set this:
<Style x:Key="tab6to12Style" TargetType="igWindow:TabItemEx">
<Setter Property="Visibility">
<MultiBinding......>
..........
</Setter>
</Style>
I have to apply that style to tab 6 to tab 12. then tab 6 to 12 lost the style that tab1 to 5 have. the tab header color and clickedon-change color is lost.
<igWindows:TabItemEx Header="Tab 9" Style="{StaticResource tab6to12Style}">
should I add BasedOn in the style definition? but what is the default style name for all?
I assume when you say that tabs 6 to 12 lose their header color and selected color that you have a style applied to them as well? Or do you have a theme applied to the XamTabControl? If you have a theme set, then that would explain why you lose the coloring.
To answer your question, yes, adding a BasedOn to the style will solve this but like you said, how would you create a style based on the default style? To do this you're going to need to add the default style used by your theme to your project first. Once this style is placed into the window/control resources, you can modify your style to include the BasedOn property like so:
<!-- Style from theme must be added first. --> <!-- Now your style can be added. --> <Style x:Key="tab6to12Style" TargetType="{x:Type igWindows:TabItemEx}" BasedOn="{StaticResource {x:Type igWindows:TabItemEx}}">
I've attached a sample that demonstrates this. My sample uses the IG Theme but this solution will work with any theme. Just make sure you replace my PrimitivesIGTheme.xaml with the proper theme file that matches the one you're using. The theme files can be found at C:\Program Files (x86)\Infragistics\NetAdvantage 2012.2\WPF\DefaultStyles\Windows.
Add PrimitiveIGTheme.xaml works for me. but do i have to put that in the same folder as my usercontrol.xaml. I tried to put it under Resources folder, it's not recognized.
Thank you!
Technically you can put it where ever you want. It's a ResourceDictionary so using it is the same as any other ResourceDictionary. In my sample I just placed it directly in the project but if you want to keep it inside a folder called 'Resources' then you'll need to change the URI that is used in XAML to load it. If you look at my sample, in MainWindow.xaml you can see the following code:
<ResourceDictionary Source="PrimitivesIGTheme.xaml"/>
If you place PrimitivesIGTheme.xaml inside a folder you need to alter the URI above to reflect that change.
<ResourceDictionary Source="Resources/PrimitivesIGTheme.xaml"/>
This one URL worked.
<ResourceDictionary Source="pack://Application:,,,/Resources/PrimitivesIGTheme.xaml" />
Cool. Glad it's working now. Let me know if you have any further questions on this matter.