C# WPF数据网格绑定不支持';不适用于嵌套对象列表
我有WPF数据网格:C# WPF数据网格绑定不支持';不适用于嵌套对象列表,c#,wpf,binding,datagrid,C#,Wpf,Binding,Datagrid,我有WPF数据网格: <DataGrid x:Name="dataGrid" Margin="0,18,0,0" AutoGenerateColumns="False" CanUserAddRows="True" CanUserDeleteRows="True" HeadersVisibility="Column" InitializingNewItem="dataGrid_InitializingNewItem"/> 所以PredictiveAttributeValue变成了对象
<DataGrid x:Name="dataGrid" Margin="0,18,0,0" AutoGenerateColumns="False" CanUserAddRows="True" CanUserDeleteRows="True" HeadersVisibility="Column" InitializingNewItem="dataGrid_InitializingNewItem"/>
所以PredictiveAttributeValue变成了对象列表而不是字符串列表
我还修改了绑定:
TextBinding = new Binding("PredictiveAttributeValues[" + i + "].Value")
然后得到下一个结果:在dataGrid中,我看到了我在ArguedLearningExampleStagridItem的构造函数中设置的所有内容,但视觉控件中的任何更改都不会反映在dataGrid.Items上。所以,我想,装订是行不通的。有什么问题
我读了一篇名为“Binding.Path Property”的msdn文章,并按照上面写的那样做了。如果通过xaml使用数据绑定,会更好。。不是代码隐藏。在xaml中,只需将窗口的DataContext设置为对象(保存数据的对象),并将控件(datacolumns)绑定到相应的对象属性即可。通过xaml使用数据绑定会更好。。不是代码隐藏。在xaml中,只需将窗口的DataContext设置为对象(保存数据),并将控件(datacolumns)绑定到相应的对象属性。
public class ArguedLearningExamplesDataGridItem
{
public bool IsUse { get; set; }
// the property below works
public List<string> PredictiveAttributeValues { get; set; }
public string DecisiveAttributeValue { get; set; }
public ArguedLearningExamplesDataGridItem()
{
IsUse = true;
PredictiveAttributeValues = new List<PredictiveAttributeValue>();
}
}
public List<PredictiveAttributeValue> PredictiveAttributeValues { get; set; }
public class PredictiveAttributeValue
{
public string Value { get; set; }
public bool IsBecauseExpression { get; set; }
public bool IsDespiteExpression { get; set; }
public PredictiveAttributeValue()
{ }
public PredictiveAttributeValue(string value, bool isBecauseExpression, bool isDespiteExpression)
{
Value = value;
IsBecauseExpression = isBecauseExpression;
IsDespiteExpression = isDespiteExpression;
}
}
TextBinding = new Binding("PredictiveAttributeValues[" + i + "].Value")