日期:2014-05-17 浏览次数:21218 次
<DataGrid x:Name="dataGrid" Grid.Row="0" ItemsSource="{Binding}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="AA" Binding="{Binding AA,Mode=TwoWay}" />
<DataGridTemplateColumn Header="BB">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding BB, Mode=TwoWay}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
ObservableCollection<class1> bindingData = new ObservableCollection<class1>();
public class class1
{
public string AA{get;set;}
public bool BB { get; set; }
}
public void InitDataBinding()
{
class1 a = new class1();
a.AA = "aaaaa";
a.BB = true;
bindingData.Add(a);
}
//绑定,初始化
dataGrid.ItemsSource = bindingData;
<StackPanel>
<TextBlock x:Name="ShowBBValue" Text="{Binding BB}" />
&l