1
比方說,我有一個DataGrid
綁定到對象的集合。這些對象具有屬性PropertyA
和PropertyB
。我想要第一列顯示PropertyA
,但是當我選擇一行時,我希望所選行僅顯示PropertyB
。我怎樣才能做到這一點?如何更改所選項目的DataGridColumn綁定?
目的
public class MyObject
{
public string PropertyA { get; set; }
public string PropertyB { get; set; }
}
的XAML
<DataGrid ItemsSource="{Binding Path=MyObjects}">
<DataGrid.Columns>
<DataGridTextColumn Header="Foo" Binding="{Binding Path=PropertyA}" />
</DataGrid.Columns>
</DataGrid>
這將顯示在數據網格中的每一行中PropertyA的值。但是,當我選擇一行時,我只希望該行更改爲顯示PropertyB。