首先,我将此用于ListView
控件本身:
ItemsSource="{Binding AllEffects}"
那么这不允许每GridViewColumn
个人绑定吗?
除了AllEffects
我还有另外两个ObservableCollection
我要绑定到另外两个GridViewColumn
:
public ObservableCollection<GPUSupportNode> GPUSupport { get; set; }
public ObservableCollection<CPUSupportNode> CPUSupport { get; set; }
public class CPUSupportNode
{
public bool IsSupported {get;set;}
}
我正试图将这两个GridViewColumns
分别挂钩到GPUSupport/CPUSupport
.IsSupported
。
现在我有:
<GridViewColumn
Width="Auto"
Header="GPU">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox
Margin="0"
HorizontalAlignment="Center"
IsChecked="{Binding GPUSupport, Mode=TwoWay}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
但它不起作用。这可能吗?
答案 0 :(得分:3)
你可以尝试像这样创建一个ViewModel类
public class MyViewModel
{
public ObservableCollection<GPUSupportNode> GPUSupport { get; set; }
public ObservableCollection<CPUSupportNode> CPUSupport { get; set; }
public ObservableCollection<TypeOfEffects> AllEffects{ get; set; }
}
并创建一个MyViewModel实例,比如ViewModel并将其初始化为Observable Collections。设置ItemsSource
ItemsSource="{Binding ViewModel}"
然后这应该有用。
<GridViewColumn
Width="Auto"
Header="GPU">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox
Margin="0"
HorizontalAlignment="Center"
IsChecked="{Binding GPUSupport, Mode=TwoWay}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>