[英]datagrid binding to an property not working
我有一个数据网格,用户可以在其中输入一些数据。 输入数据后,他们单击按钮以上传数据。 但是,我遇到了一些数据无法绑定的问题,这与我期望的一样。
数据网格绑定到类型为ObservableCollection HoldingLogEQ的名为HldLogEQ的列表。
当我在数据上传之前进行调试时,ISIN和Sedol属性均为null,这是不正确的。 我以为下面的行是绑定数据的正确方法? 我想念什么?
<DataGridTextColumn Header="Sedol" IsReadOnly="False" Binding="{Binding Security.Sedol, Mode=TwoWay}"/>
HoldingLoq类别
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));
}
}
安全编号类别
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 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>
可能需要添加路径。
Binding="{Binding Path=Security.Sedol, Mode=TwoWay}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.