WPF DATAGIRD更新数据源的问题
<sdk:DataGrid x:Name="dgTest" Margin="0,0,0,0" VerticalAlignment="Top" Height="100" AutoGenerateColumns="False" FontSize="14">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn CanUserReorder="True" Binding="{Binding 合格证号,Mode=TwoWay, ValidatesOnDataErrors=True}" CanUserResize="True" CanUserSort="True" Width="Auto" Header="合格证号" />
<sdk:DataGridTextColumn CanUserReorder="True" Binding="{Binding 设备编号,Mode=TwoWay, ValidatesOnDataErrors=True}" CanUserResize="True" CanUserSort="True" Width="Auto" Header="设备编号" />
</sdk:DataGrid.Columns>
</sdk:DataGrid>
<TextBox x:Name="txt全格证号" HorizontalAlignment="Left" Height="23" Margin="10,150,0,0" TextWrapping="Wrap" Text="{Binding SelectedItem.合格证号, ElementName=dgTest, Mode=TwoWay}" VerticalAlignment="Top" Width="120"/>
<TextBox x:Name="txt设备编号" HorizontalAlignment="Left" Height="23" Margin="224,150,0,0" TextWrapping="Wrap" Text="{Binding SelectedItem.设备编号, ElementName=dgTest, Mode=TwoWay}" VerticalAlignment="Top" Width="120"/>
TestDataCollection list = new TestDataCollection()
{
new TestData(){ 合格证号="01234", 设备编号="OX001"},
new TestData(){ 合格证号="111", 设备编号="11"},
};
dgTest.ItemsSource = list;
public class TestDataCollection : ObservableCollection<TestData>
{ }
public class TestData
{
public string 合格证号 { set;get;}
public string 设备编号 { set; get; }
}