我有一個DataGrid是由用戶,XAML填寫:雙向綁定需要路徑或XPath,DataGrid的結合
<DataGrid ItemsSource="{Binding Path=Input.InloopAangepast, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Path=TypeOppervlak}"/>
<DataGridTextColumn Binding="{Binding Path=TypeAfstroming}"/>
<DataGridTextColumn Binding="{Binding Path=Parameters[0].Double}"/>
<DataGridTextColumn Binding="{Binding Path=Parameters[1].Double}"/>
<DataGridTextColumn Binding="{Binding Path=Parameters[2].Double}"/>
<DataGridTextColumn Binding="{Binding Path=Parameters[3].Double}"/>
<DataGridTextColumn Binding="{Binding Path=Parameters[4].Double}"/>
<DataGridTextColumn Binding="{Binding Path=Parameters[5].Double}"/>
<DataGridTextColumn Binding="{Binding Path=Parameters[6].Double}"/>
</DataGrid.Columns>
</DataGrid>
視圖模型:
InloopAangepast = new ObservableCollection<Inloop>();
和:
public class Inloop : INotifyPropertyChanged
{
public Inloop()
{
Parameters = new ObservableCollection<InloopParameter>();
}
private string _typeOppervlak;
private string _typeAfstroming;
private string _omschrijving;
public ObservableCollection<InloopParameter> _parameters;
public string TypeOppervlak
{
get
{
return _typeOppervlak;
}
set
{
_typeOppervlak = value;
if (PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs("TypeOppervlak"));
}
}
}
public string TypeAfstroming
{
get
{
return _typeAfstroming;
}
set
{
_typeAfstroming = value;
if (PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs("TypeAfstroming"));
}
}
}
public string Omschrijving
{
get
{
return _omschrijving;
}
set
{
_omschrijving = value;
if (PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs("Omschrijving"));
}
}
}
public ObservableCollection<InloopParameter> Parameters
{
get
{
return _parameters;
}
set
{
_parameters = value;
if (PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs("Parameters"));
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
public class InloopParameter : INotifyPropertyChanged
{
public InloopParameter()
{
}
private string _naam;
private string _string;
private double? _double;
public string Naam
{
get
{
return _naam;
}
set
{
_naam = value;
if (PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs("Naam"));
}
}
}
public string String
{
get
{
return _string;
}
set
{
_string = value;
if (PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs("String"));
}
}
}
public double? Double
{
get
{
return _double;
}
set
{
_double = value;
if (PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs("Double"));
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
我可以輸入前兩個字段(TypeOppervlak和TypeAfstroming),但是當我輸入其他字段之一時出現錯誤「雙向綁定需要Path或XPath「。我究竟做錯了什麼?
非常感謝你,我曾嘗試分配一個集合,但沒有添加任何「InloopParameter的」 – user3692104 2014-10-04 11:56:48
很高興幫助隊友..! – 2014-10-04 12:00:07