background preloader

TabControl

Facebook Twitter

TabControl Class (System.Windows.Controls) Represents a control that contains multiple items that share the same space on the screen. [TemplatePartAttribute(Name = "PART_SelectedContentHost", Type = typeof(ContentPresenter))] [StyleTypedPropertyAttribute(Property = "ItemContainerStyle", StyleTargetType = typeof(TabItem))] public class TabControl : Selector <TabControl> Items </TabControl> The TabControl type exposes the following members. Customizing the TabControl Control <TabControl><TabItem><TabItem.Header><StackPanel Orientation="Horizontal"><Ellipse Width="10" Height="10" Fill="DarkGray"/><TextBlock>Tab 1</TextBlock></StackPanel></TabItem.Header><StackPanel><TextBlock>Enter some text</TextBlock><TextBox Name="textBox1" Width="50"/></StackPanel></TabItem><TabItem Header="Tab 2"><!

--Bind TextBlock.Text to the TextBox on the first TabItem. --><TextBlock Text="{Binding ElementName=textBox1, Path=Text}"/></TabItem></TabControl> .NET Framework Supported in: 4.5.1, 4.5, 4, 3.5, 3.0 .NET Framework Client Profile Supported in: 4, 3.5 SP1. WPF Tab Control - Inside and Out. When it comes to the WinForm's Tab Control, there was a lot left to be desired. If you had to make major changes to either looks or functionality, you were better off just writing your own tab control completely from scratch. The WPF Tab Control makes major strides in the right direction, and because of the power of WPF styles and control templates, you pretty much have complete control over how the tab control looks and feels. This tutorial is going to introduce you to the tab control and demonstrate how to re-skin it look like how you want. Let's start off easy by simply putting a regular old tab control in a window and adding a couple of tabs.

The above code gives you a pretty standard looking tab control like the one pictured below. Like most other WPF controls, the contents of a TabItem can be most any other WPF control. Let's look at a tab with an image set as the content. That should look something like the following: That's enough of the simple stuff. WPF TabItems With Close Button. One of the most common questions I've seen regarding the TabControl in Windows Forms was how to add a close button to each tab (similar to seen on tabs in Internet Explorer 7). Although there were some solutions available the results weren't quite satisfactory and often requiring to rewrite the whole control from scratch. Recently I faced the same challenge working on the TSRI project. It turned out that in WPF this pretty straightforward task and in this article I'm going to show all the steps required to complete it.

To follow the discussion you can download the demo code first: Download the source code We start by creating a new custom control deriving from TabItem that implements this behavior. I'll name it CloseableTabItem. public class CloseableTabItem : TabItem { static CloseableTabItem() { DefaultStyleKeyProperty.OverrideMetadata(typeof(CloseableTabItem), new FrameworkPropertyMetadata(typeof(CloseableTabItem))); } } Before we add more code let's create the control template first. WPF Single Row Tab Control. I’ve been working through a few UI related requests on my current project. One such request is to alter the appearance of the WPF TabControl to have a single row of tabs. The default behavior is to wrap the tabs beyond the single line as space is needed. This is the default behavior I’d like mine to look more like this: So it may have taken a little while to figure it out…but now I know…and I will share with the world.

The first thing you need to do is have an empty window and add a TabControl to it. 1: <Window 2: xmlns=" 3: xmlns:x=" 4: x:Class="WpfApplication2.TabWindow" 5: x:Name="Window" 6: Title="TabWindow" 7: Width="640" Height="480"> 9: <Grid x:Name="LayoutRoot"> 10: <TabControl> 11: <TabItem Header="TabItem"> 12: <Grid/> 13: </TabItem> 14: <TabItem Header="TabItem"> 15: <Grid/> 16: </TabItem> 17: </TabControl> 18: </Grid> 19: </Window> Next you need to edit the template for the TabControl.

TabControl focus problems. I'm having a generally miserable time with focus issues. What I'd like to do: use a TabControl to provide an Mutiple-document interface (since WPF doesn't support MDI). The issue: my undo engine needs to switch windows in the TabControl in order to show the object affected by an undo or redo. But I can't figure out how to switch tabs without sending focus to the Header content of the TabItem, instead of leaving it in the Content. I coopted the BringIntoView()/RequestBringIntoViewEvent mechanism, which seemed reasonable, but may be the cause of the problem. But the behaviour is strange. In the code that follows, GetTabContainer() returns the TabItem that contains the target object. Here's the behaviour. Attempts to set the focus to somewhere more reasonable fail. I'm guessing that its an interaction between the layout engine and focus engine; but I'm not sure how to begin to try addressing it.

Creating an Outlook Navigation Pane by Restyling a.