问题描述
在我的视图模型
I类有一个静态属性 AllSupport
,但我无法弄清楚如何绑定正确。 ListView控件已经绑定到一个ObservableCollection AllEffects
具有 AllSupport
静态属性。
In my ViewModel
class I have a static property AllSupport
but I can't figure out how to bind it correctly. The ListView is already binded to an ObservableCollection AllEffects
that has the AllSupport
static property.
我用这样的:
<GridViewColumn
Width="Auto"
Header="GPU">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox
Margin="0"
HorizontalAlignment="Center"
IsChecked="{Binding AllSupport[HardwareType].SupportList.IsSupported, Mode=TwoWay}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
它有
AllEffects
是的ObservableCollection
EffectViewModel
所谓静态属性 AllSupport
这是类型:词典&LT; HardwareType,名单,其中,EffectSupport&GT;&GT;
其中:
AllEffects
is ObservableCollection
of EffectViewModel
where it has a static property called AllSupport
which is of type:Dictionary<HardwareType, List<EffectSupport>>
where:
HardwareType
是一个枚举,和 EffectSupport
的是,有一个叫做布尔属性类的实例则isSupported
。
HardwareType
is an enum, andEffectSupport
is an instance class that has a boolean property called IsSupported
.
我也试过,但随后它抱怨找不到则isSupported
在视图模型
类:
I also tried this but then it complains that it can't find IsSupported
on the ViewModel
class:
IsChecked="{Binding AllSupport[HardwareType].SupportList, Path=IsSupported
任何想法,如何指定绑定?
Any ideas, how to specify this binding?
推荐答案
您可以使用 X:静态
类是静态的还是不来访问静态成员
You can use x:Static
whether the class is static or not to access static members.
未经测试的:
IsChecked="{Binding [HardwareType], Source={x:Static prefix:EffectViewModel.AllSupport}}"
和你需要一个 preFIX
来访问您的视图模型的命名空间。
and you'll need a prefix
to access your view model's namespace.
这篇关于如何将数据绑定到一个静态属性在非静态类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!