Edit: added an example
You should be able to accomplish this using databinding. If Node is a custom object, you will want to either suport INotifyPropertyChange, or implement the Label property as a dependency property. (I'm not sure what the convention is, I would guess that if Node is intrinsically a UI object, then use a dependency property, and if it's not then implement INotifyPropertyChanged.
Example:
The Node object:
public class Node: System.ComponentModel.INotifyPropertyChanged
{
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
public string Label
{
get { return this._Label; }
set
{
this._Label = value;
this.OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("Label"));
}
}
private string _Label;
protected virtual void OnPropertyChanged(System.ComponentModel.PropertyChangedEventArgs propertyChangedEventArgs)
{
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if (propertyChanged != null)
propertyChanged(this, propertyChangedEventArgs);
}
}
The code behind your form (this method sets up your databinding in code, you could also set up the databinding in the XAML):
public partial class MainWindow : Window
{
public Node TheNode { get; set; }
public MainWindow()
{
InitializeComponent();
this.TheNode = new Node();
this.DataContext = this;
this.Tab1.SetBinding(System.Windows.Controls.TabItem.HeaderProperty, "TheNode.Label");
this.TheNode.Label = "Test";
}
}
The XAML for your form
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<TabControl>
<TabItem Name="Tab1"/>
</TabControl>
</Grid>
When you databind, WPF will detect that your Node object implements INotifyPropertyChanged, and it will subscribe the PropertyChanged event automatically.
(notice that in the MainWindow code, I set the binding and then I set the value of the Node.Label -- the tab header detects it and updates).