我有一个选项卡控件...动态添加到哪些选项卡项。每个选项卡项都包含一个数据网格我的选项卡控件是
<TabControl Grid.Row="1" Name="tabControl" ItemsSource="{Binding TabItems}" ContentTemplate="{DynamicResource DataTemplate1}" >
</TabControl>
模板...
<Window.Resources>
<DataTemplate x:Key="DataTemplate1">
<Grid>
<DataGrid ItemsSource="{Binding Path=GridSource,UpdateSourceTrigger=PropertyChanged}"></DataGrid>
</Grid>
</DataTemplate>
</Window.Resources>
public MainWindowViewModel()
{
NewCmnd = new RelayCommand(NewCommandExecute, NewCommandCanExecute);
TabItems = new ObservableCollection<TabItem>();
GridSource = new DataTable();
GridSource.Columns.Add("Column1");
GridSource.Columns.Add("Column2");
GridSource.Columns.Add("Column3");
}
public ObservableCollection<TabItem> TabItems
{
get;
set;
}
public DataTable GridSource
{
get
{
return dt;
}
set
{
dt = value;
OnPropertyChanged(new PropertyChangedEventArgs("GridSource"));
}
}
我将标签项添加为
TabItems.Add(new TabItem());
DataRow dr = GridSource.NewRow();
dr["Column1"] = "abc";
dr["Column2"] = "abc";
dr["Column3"] = "abc";
GridSource.Rows.Add(dr);
但我的用户界面没有更新..谁能告诉我可能的原因?