Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would do it like this (The code is for a WPF solution, have overlooed the WinForm-Tag. But should work similar.):</p> <p>MyTabItem.xaml.cs</p> <pre><code>public partial class MyTabItem : TabItem, INotifyPropertyChanged { #region PropertyChanged public event PropertyChangedEventHandler PropertyChanged; void OnPropertyChanged(string propName) { if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propName)); } #endregion #region Properties private string myTitle; public string MyTitle { get { return myTitle; } set { myTitle = value; OnPropertyChanged("MyTitle"); } } private string myContent; public string MyContent { get { return myContent; } set { myContent = value; OnPropertyChanged("MyContent"); } } #endregion public MyTabItem() { InitializeComponent(); } } </code></pre> <p>MyTabItem.xaml</p> <pre><code>&lt;TabItem x:Class="WpfApplication1.MyTabItem" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" DataContext="{Binding RelativeSource={RelativeSource self}}"&gt; &lt;TabItem.Header&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;TextBlock Text="{Binding MyTitle}"/&gt; &lt;/StackPanel&gt; &lt;/TabItem.Header&gt; &lt;TabItem.Content&gt; &lt;Grid&gt; &lt;TextBlock Text="{Binding MyContent}" Background="Azure"/&gt; &lt;/Grid&gt; &lt;/TabItem.Content&gt; &lt;/TabItem&gt; </code></pre> <p>MainWindow.xaml.cs</p> <pre><code>public MainWindow() { InitializeComponent(); var tab = new MyTabItem {MyContent = "Content", MyTitle = "Title"}; MyTabControl.Items.Add(tab); } </code></pre> <p>MainWindow.xaml</p> <pre><code>&lt;Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt; &lt;Grid&gt; &lt;TabControl x:Name="MyTabControl"/&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload