2
在Silverlight應用程序創建標籤的物品在代碼中動態(的MainView的代碼隱藏):Silverlight 4中的TabControl MVVM選項卡頭綁定
TabItem tab = new TabItem();
CustomerView view = new CustomerView();
view.DataContext = customerViewModel; //or tab.DataContext = customerViewModel;??
tab.Content = view;
DataTemplate template = this.Resources["CustomTabItemHeader"] as DataTemplate;
tab.HeaderTemplate = template;
tabControl.Items.Add(tab);
CustomTabItemHeader(在MainView.xaml)看起來像:
<UserControl.Resources>
<DataTemplate x:Key="CustomTabItemHeader">
<TextBlock Text="{Binding Path=DisplayName}"/>
</DataTemplate>
</UserControl.Resources>
CustomerViewModel具有DisplayName屬性,它實現INotifyPropertyChanged接口。但DisplayName不顯示在選項卡標題中。有人可以解釋我爲什麼嗎?