我有一个数据网格,用户可以在其中输入一些数据。一旦他们输入了数据,他们就会点击一个按钮来上传数据。但是,我遇到了一些问题,数据没有像我预期的那样具有约束力。
datagrid绑定到一个名为HldLogEQ的列表,类型为ObservableCollection HoldingLogEQ。
当我在上传数据之前进行调试时,ISIN和Sedol属性都为null,这是不正确的。我认为下面的行是绑定数据的正确方法?我错过了什么?
<DataGridTextColumn Header="Sedol" IsReadOnly="False" Binding="{Binding Security.Sedol, Mode=TwoWay}"/>
HoldingLoq Class
public class HoldingLogEQ : INotifyPropertyChanged
{
public DateTime DateEffective
{
get
{
return _dateEffective;
}
set
{
_dateEffective = value;
OnPropertyChanged("DateEffective");
}
}
public SecruityID Security
{
get
{
return _security;
}
set
{
_security = value;
OnPropertyChanged("Security");
}
}
public List<Fund> Funds
{
get
{
return _funds;
}
set
{
_funds = value;
OnPropertyChanged("Funds");
}
}
private DateTime _dateEffective;
private SecruityID _security = new SecruityDescriptive();
private List<Fund> _funds;
public event PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
安全ID类
public class SecurityID : INotifyPropertyChanged
{
public string ISIN
{
get
{
return _isin;
}
set
{
_isin = value;
OnPropertyChanged("ISIN");
}
}
public string Sedol
{
get
{
return _sedol;
}
set
{
_sedol = value;
OnPropertyChanged("Sedol");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
private string _isin;
private string _sedol;
#endregion
}
的Datagrid
<DataGrid Grid.Row="1"
x:Name="dgHldRGHTS"
ItemsSource="{Binding HldLogEQ, UpdateSourceTrigger=PropertyChanged}"
Style="{StaticResource DataGridTemplate1}"
ColumnHeaderStyle="{StaticResource DG_ColumnHeaderCenter1}"
RowStyle="{StaticResource DG_Row1}"
CellStyle="{StaticResource DG_Cell1}"
RowHeaderStyle="{StaticResource DG_RowHeader1}"
RowDetailsTemplate="{StaticResource DG_RowDetail}"
AutoGenerateColumns="False"
HorizontalAlignment="Stretch"
Background="Silver"
Margin="50,0,50,50"
CanUserDeleteRows="True"
CanUserAddRows="True"
RowHeaderWidth="30">
<DataGrid.Columns>
<DataGridTextColumn Header="Date Effective" IsReadOnly="False" Binding="{Binding DateEffective, StringFormat={}\{0:dd-MMM-yy\}, Mode=TwoWay}" MinWidth="75"/>
<DataGridTextColumn Header="ISIN" IsReadOnly="False" Binding="{Binding Security.ISIN, Mode=TwoWay}" MinWidth="75"/>
<DataGridTextColumn Header="Sedol" IsReadOnly="False" Binding="{Binding Security.Sedol, Mode=TwoWay}" MinWidth="75"/>
<DataGridTextColumn Header="Name" IsReadOnly="False" Binding="{Binding Security.Name, Mode=TwoWay}" MinWidth="200"/>
</DataGrid.Columns>
</DataGrid>
答案 0 :(得分:1)
可能需要添加路径。
Binding="{Binding Path=Security.Sedol, Mode=TwoWay}"