wpf datagrid行绑定类的属性不起作用

时间:2014-08-11 10:05:36

标签: wpf binding datagrid

我想将datagrid的行与class的属性绑定,但是它不起作用

  <DataGrid Name="ProductsGrid" Background="AliceBlue"  Margin="0, 10, 0, 0" AutoGenerateColumns="False" 
     CanUserAddRows="False" EnableRowVirtualization="True" ItemsSource="{Binding}">

     <DataGrid.Columns>
         <DataGridTextColumn Header="Product" Width="*" IsReadOnly="True" Binding="{Binding ProductName}"/>
         <DataGridTextColumn Header="HedgeStyle" Width="*" IsReadOnly="True" Binding="{Binding Positions.hedgeStyle}"/>

     </DataGrid.Columns>
  </DataGrid>

datagrid的绑定类结构是:

 public class NotifiedTest : INotifyPropertyChanged
 {
    public string ProductName;

    private BopuCtpPositions _Positions;
    public BopuCtpPositions Positions
    {
        get
        {
            return this._Positions;
        }
        set
        {
            if (value != this._Positions)
            {
                this._Positions = value;
                NotifyPropertyChanged("Positions");
            }
        }
    }
 }

内部课程&#34;职位&#34;结构:

public class BopuCtpPositions
{
    public int hedgeStyle;
}

1 个答案:

答案 0 :(得分:0)

BopuCtpPositions也应该由INotifyPropertyChanged继承。在我这样做之后,它可以正常工作