How can I add a style to a TabItem that is used in the TabControl ?
Here is a custom style that changes the look and feel of the tabs (TabItems) in the corresponding window. [XAML] <Style TargetType=’TabItem’> <Setter Property=’BorderThickness’ Value=’3’/> <Setter Property=’BorderBrush’ Value=’Red’/> <Setter Property=’Background’ Value=’LightBlue’/> <Setter Property=’VerticalContentAlignment’ Value=’Center’/> <Setter Property=’HorizontalContentAlignment’ Value=’Center’/> <Setter Property=’Template’> <Setter.Value> <ControlTemplate TargetType='{x:Type TabItem}’> <Border> <Grid> <Grid> <Border CornerRadius=’3,3,0,0′ Background='{TemplateBinding Background}’ BorderBrush='{TemplateBinding BorderBrush}’ BorderThickness='{TemplateBinding BorderThickness}’/> </Grid> <Border BorderThickness='{TemplateBinding BorderThickness}’ Padding='{TemplateBinding Padding}’> <ContentPresenter ContentSource=’Header’ HorizontalAlignment='{TemplateBinding HorizontalContentAlignment}’ VerticalAlignment='{TemplateBinding VerticalContentAlignment}’/> </Border> </Grid> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> This is how the tabs look with the above style applied on them:
How do I make the tabs in a TabControl appear on the bottom instead of on top?
Set the ‘TabStripPlacement’ enum property to ‘Bottom’. The possible enum values of this property are Left, Top, Right and Bottom.
How do I validate the current tab before selection changes to another tab on user click?
Unfortunately, WPF doesn’t provide a straight forward way of validating a tab page’s content before switching to a new tab, in the first version. One workaround is to listen to the TabItem’s PreviewLostKeyboardFocus event and mark it as Handled as shown below. [C#] public TabValidation() { InitializeComponent(); foreach (TabItem item in tabControl1.Items) { item.PreviewLostKeyboardFocus += new KeyboardFocusChangedEventHandler(item_PreviewLostKeyboardFocus); } } void item_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) { // sender is the TabItem. if (this.ValidateTab() == false) e.Handled = true; }
How do I bind a flat table/list containing self-referencing data to a TreeView to render it in a hierarchical view?
The following article illustrates how you can first shape a flat table or list into a hierarchical list and then bind the resultant hierachy to the tree: .NET – LINQ AsHierarchy() extension method
How do I listen to text changed events in a ComboBox in editable mode?
Unfortunately, the first version of WPF does not provide a TextChanged event for a ComboBox like the one available for a TextBox. So, a workaround like the following is required: [C#] public Window1() { InitializeComponent(); this.comboBox.Loaded += delegate { TextBox editTextBox = comboBox.Template.FindName(‘PART_EditableTextBox’, comboBox) as TextBox; if (editTextBox != null) { editTextBox.TextChanged += delegate { MessageBox.Show(comboBox.Text); }; } }; }