Close button in tabControl

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

TabControl with Add New Tab Button (+)

An almost complete solution using IEditableCollectionView: ObservableCollection<ItemVM> _items; public ObservableCollection<ItemVM> Items { get { if (_items == null) { _items = new ObservableCollection<ItemVM>(); var itemsView = (IEditableCollectionView)CollectionViewSource.GetDefaultView(_items); itemsView.NewItemPlaceholderPosition = NewItemPlaceholderPosition.AtEnd; } return _items; } } private DelegateCommand<object> _newCommand; public DelegateCommand<object> NewCommand { get { if (_newCommand == null) { _newCommand = new DelegateCommand<object>(New_Execute); } return … Read more

In C# WPF, why is my TabControl’s SelectionChanged event firing too often?

The TabControl.SelectionChanged is the same event as a ComboBox.SelectionChanged It originates from Selector.SelectionChanged. So, if you do not mark your event as handled in your event handler, it will bubble up the tree, and eventually arrive at your TabControl, which is causing this “firing too often” issue. Mark your event as handled in your SelectionChanged … Read more

How to create trapezoid tabs in WPF tab control

I tried to find some control templates or solutions for this problem on internet, but I didn’t find any “acceptable” solution for me. So I wrote it in my way and here is an example of my first (and last=)) attempt to do it: <Window x:Class=”TabControlTemplate.Window1″ xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” xmlns:src=”https://stackoverflow.com/questions/561931/clr-namespace:TabControlTemplate” Title=”Window1″ Width=”600″ Height=”400″> <Window.Background> <LinearGradientBrush StartPoint=”0,0″ … Read more

How do I disable visual styles for just one control, and not its children?

Add a new class to your project and paste the code shown below. Build. Drop the new control from the top of the toolbox onto your form. Visual styles of the child controls are preserved. using System; using System.Windows.Forms; using System.Runtime.InteropServices; public class FixedTabControl : TabControl { [DllImportAttribute(“uxtheme.dll”)] private static extern int SetWindowTheme(IntPtr hWnd, string … Read more

Set TabPage Header Color

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

Hide Tab Header on C# TabControl

Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form. It shows the tabs at design time so you can easily switch between them while designing. They are hidden at runtime, use the SelectedTab or SelectedIndex property in … Read more

How to fix this behavior in a WPF TabControl?

A simplified example. Collection item: using Simplified; namespace AddTabItem { public class TabVm : BaseInpc { string _header; bool _isPlaceholder; private string _text; public string Header { get => _header; set => Set(ref _header, value); } public bool IsPlaceholder { get => _isPlaceholder; set => Set(ref _isPlaceholder, value); } public string Text { get => … Read more