【发布时间】:2011-02-06 04:32:18
【问题描述】:
我已阅读 this very related question here on SO,由于答案中的链接,它非常有帮助。我现在只是遇到了一个问题,现在要进行额外的步骤并使其全部使用 MVVM 模式。
假设我有我的 ViewModel,它(甚至模型)可以定义一个枚举:
public enum MyTypes { Type1, Type2, Type3 };
我想将它数据绑定到我的 GUI 中的 ComboBox。根据文章,我将使用 ObjectDataProvider 来调用 MyTypes 上的 Enum.GetValues() 方法。所以我必须将 MyTypes 作为 MethodParameter 传递。但是你如何传递类型?我尝试了各种方法,比如在 XAML 中添加对命名空间的引用:
<Window.Resources>
<ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="TipHandlingValues">
<ObjectDataProvider.MethodParameters>
<!-- what goes here? it's totally wrong. -->
<my:MyTypes />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources>
我放在那里的几乎所有内容都无法编译。有谁知道如何克服这个小障碍?
【问题讨论】:
标签: wpf data-binding mvvm combobox enums