【发布时间】:2010-09-15 03:51:30
【问题描述】:
在 silverlight 应用程序中,我在代码中动态创建选项卡项(MainView 的代码隐藏):
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 不会显示在选项卡标题中。谁能解释一下为什么?
【问题讨论】:
标签: silverlight mvvm tabcontrol