我正在尝试将数据网格绑定到集合,但我不知道哪些是集合的列。所以我尝试将列绑定到传递给视图的属性。
我的代码是:
<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”。