简体   繁体   English

绑定到属性的数据网格不起作用

[英]datagrid binding to an property not working

I have a datagrid where a user can enter some data. 我有一个数据网格,用户可以在其中输入一些数据。 Once they have entered the data they click a button to upload the data. 输入数据后,他们单击按钮以上传数据。 However I am having some issues with the data not binding as I expect. 但是,我遇到了一些数据无法绑定的问题,这与我期望的一样。

The datagrid is bound to a list called HldLogEQ of type ObservableCollection HoldingLogEQ. 数据网格绑定到类型为ObservableCollection HoldingLogEQ的名为HldLogEQ的列表。

When I debug before the data is uploaded the ISIN and Sedol properties are both null which is incorrect. 当我在数据上传之前进行调试时,ISIN和Sedol属性均为null,这是不正确的。 I thought the line below was the correct way to bind the data? 我以为下面的行是绑定数据的正确方法? What am I missing? 我想念什么?

<DataGridTextColumn Header="Sedol" IsReadOnly="False" Binding="{Binding Security.Sedol, Mode=TwoWay}"/>

HoldingLoq Class 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));
        }
    }

Security Id class 安全编号类别

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>

可能需要添加路径。

Binding="{Binding Path=Security.Sedol, Mode=TwoWay}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM