DataGridColumn动态(参数)绑定到集合的列

时间:2013-10-28 08:48:07

标签: wpf binding datagridcolumn

我正在尝试将数据网格绑定到集合,但我不知道集合的哪些列。 所以我尝试将列绑定到传递给视图的属性。

我的代码是:

  <FrameworkElement x:Key="ProxyElement" DataContext="{Binding ElementName=_VMItemSelector}"/>

<WPFCtrlDg:SelfBindingDataGrid x:Name="_sbdgAvailableItems" ScrollViewer.VerticalScrollBarVisibility="Auto"
                    ItemsSource="{Binding Path=Availables}"
                    SelectedItem="{Binding Path=CurrentAvailableItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                    IsReadOnly="{Binding DataContext.IsReadOnly,
                    Source={StaticResource ProxyElement},
                    Mode=OneWay}">
            <WPFCtrlDg:SelfBindingDataGrid.Columns>
                <WPFCtrlDg:ExtDataGridTextColumn Header="{Binding DataContext.DetailBinding,
                                                          Source={StaticResource ProxyElement},
                                                          Mode=OneWay}"  
                                                          Tag="CD_FUNCTION" 
                                                          Visibility="Hidden"/>
                <WPFCtrlDg:ExtDataGridTextColumn Header="{Binding DataContext.RightColumnHeader,
                                                          Source={StaticResource ProxyElement},
                                                          Mode=OneWay}"  
                                                          Binding="{Binding DataContext.RightColumnHeader,
                                                          Source={StaticResource ProxyElement}, 
                                                          Mode=OneWay}" 
                                                          Width="*"/>

并且在视图中我有

    private string _rightColumnHeader;
    public string RightColumnHeader
    {
        get { return _rightColumnHeader; }
        set { _rightColumnHeader = value; }
    }

该值设置为“DS_FUNCTION”,这是我绑定的集合的字段,但我在dataGrid中看到的是集合中每个元素的“DS_FUNTION”。

0 个答案:

没有答案