0
我已經定義了下面的XAML。該綁定填充了DataGridComboBoxColumn,如果我同時在組合框中選擇PartNumber,則需要在DataGridTextColumn中綁定另一個屬性(PartName)值。我怎麼能在DataGridTextColumn中做這個綁定?如何在Datagrid中定義依賴關係綁定
<Window.Resources>
<ObjectDataProvider x:Key="RecordValues"
ObjectType="{x:Type local:RecordTemp}"
MethodName="GetPersonList">
</ObjectDataProvider>
</Window.Resources>
<Grid>
<Grid>
<DataGrid AutoGenerateColumns="False"
ItemsSource="{Binding}"
Margin="10"
Name="dataGrid1">
<DataGrid.Columns>
<DataGridComboBoxColumn Header="Combo"
Width="300"
SelectedItemBinding="{Binding Values}"
DisplayMemberPath="PartNumber"
ItemsSource="{Binding Source={StaticResource RecordValues}}" />
<DataGridTextColumn Header="Order Name"
Binding="" />
</DataGrid.Columns>
</DataGrid>
</Grid>
</Grid>
在下面的代碼定義的C#,要完成這一
ObservableCollection<RecordTemp> RecordsTemp = new ObservableCollection<RecordTemp>();
RecordsTemp.Add(new RecordTemp());
RecordsTemp.Add(new RecordTemp());
dataGrid1.DataContext = RecordsTemp;
public class RecordTemp
{
List<PartsList> _value = new List<PartsList>();
public RecordTemp()
{
_value.Add(new PartsList() { PartName = "One", PartNumber = "1", PartQuantity = 20 });
_value.Add(new PartsList() { PartName = "Two", PartNumber = "2", PartQuantity = 10 });
}
public List<PartsList> value
{
get { return _value; }
set { _value = value; }
}
public List<PartsList> GetPersonList()
{
return _value;
}
}
public class PartsList
{
public string PartName { get; set; }
public double PartQuantity { get; set; }
public string PartNumber { get; set; }
}
優秀的一個..謝謝 – Smaug