WPF Tab Control: How do I get the currently selected tab?
TabControl.SelectedItem is the selected tab. cast it to a TabItem to get the properties. What I mostly do is bind it to a viewmodel.
TabControl.SelectedItem is the selected tab. cast it to a TabItem to get the properties. What I mostly do is bind it to a viewmodel.
If you want to color the tabs, try the following code: this.tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed; this.tabControl1.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.tabControl1_DrawItem); private Dictionary<TabPage, Color> TabColors = new Dictionary<TabPage, Color>(); private void SetTabHeader(TabPage page, Color color) { TabColors[page] = color; tabControl1.Invalidate(); } private void tabControl1_DrawItem(object sender, DrawItemEventArgs e) { //e.DrawBackground(); using (Brush br = new SolidBrush (TabColors[tabControl1.TabPages[e.Index]])) { e.Graphics.FillRectangle(br, … Read more
Without deriving a class, here is a neat snippet: http://www.dotnetthoughts.net/implementing-close-button-in-tab-pages/ Set the DrawMode property of the Tab Control to OwnerDrawFixed. This property decides whether system or developer can paint the captions. Add the code in the DrawItem event of the Tab Control – This event will be invoked for painting each Tab Page. //This code … Read more
First of all, there are two templates involved here: TabControl.ItemTemplate, used to render the TabItem headers TabControl.ContentTemplate, used to render the TabItem contents If you don’t set these properties explicitly then WPF will attempt to resolve them elsewhere. It will walk up the logical tree looking for a resource telling it how to render your … Read more
In the properties of the tab control there’s a TabPages collection. You should be able to shuffle them around in there. Just click the ellipses next to TabPages and a dialog will appear allowing you to move each one up or down in the order.
Try this style instead, it modifies the template itself. In there you can change everything you need to transparent: <Style TargetType=”{x:Type TabItem}”> <Setter Property=”Template”> <Setter.Value> <ControlTemplate TargetType=”{x:Type TabItem}”> <Grid> <Border Name=”Border” Margin=”0,0,0,0″ Background=”Transparent” BorderBrush=”Black” BorderThickness=”1,1,1,1″ CornerRadius=”5″> <ContentPresenter x:Name=”ContentSite” VerticalAlignment=”Center” HorizontalAlignment=”Center” ContentSource=”Header” Margin=”12,2,12,2″ RecognizesAccessKey=”True”> <ContentPresenter.LayoutTransform> <RotateTransform Angle=”270″ /> </ContentPresenter.LayoutTransform> </ContentPresenter> </Border> </Grid> <ControlTemplate.Triggers> <Trigger Property=”IsSelected” Value=”True”> … Read more
I got resolve it with this tip WPF TabControl: Turning Off Tab Virtualization at http://www.codeproject.com/Articles/460989/WPF-TabControl-Turning-Off-Tab-Virtualization this a class of TabContent with property IsCached.
You can use a Style applied to TabItem with a DataTrigger that will collapse it if the parent TabControl has only one item: <Grid xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:sys=”clr-namespace:System;assembly=mscorlib” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”> <Grid.Resources> <x:Array x:Key=”tabData” Type=”{x:Type sys:String}”> <sys:String>do</sys:String> <sys:String>re</sys:String> <sys:String>mi</sys:String> </x:Array> </Grid.Resources> <TabControl ItemsSource=”{StaticResource tabData}”> <TabControl.ItemContainerStyle> <Style TargetType=”{x:Type TabItem}”> <Style.Triggers> <DataTrigger Binding=”{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TabControl}}, Path=Items.Count}” Value=”1″> <Setter Property=”Visibility” … Read more
Actually, it’s very straight forward to hide the tab strip. You just set each TabItems Visibility to Collapsed. You still see the tab content,…just not the tab header itself.
I think the answer is much easier. To hide the tab you just can use the way you already tried or adressing the TabPage itself. TabControl1.TabPages.Remove(TabPage1) ‘Could be male TabControl1.TabPages.Remove(TabPage2) ‘Could be female a.s.o. Removing the TabPage does not destroy it and the controls on it. To show the corresponding tab again just use the … Read more