2011-09-02 107 views
2

我有一个类BatchInfoViewModel包含一个枚举:WPF数据绑定枚举

namespace MyStuff.ViewModel 
{ 
    public class BatchInfoViewModel : ObservableObject 
    { 
     public enum TimeFrame 
     { 
      Today, 
      Last7days, 
      Last30days, 
      Last6months, 
      Last12months, 
      All 
     } 
    } 
} 

和用户控制“BatchInfoView”使用一个BatchInfoViewModel和我想要一个组合框在该视图绑定,给时间表枚举模型,但是我找到的每个资源都显示了我认为是我正在使用的方法,但是我在运行时不断发现Type未找到异常。

<UserControl x:Class="MyStuff.View.BatchInfoView" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:view="clr-namespace:MyStuff.View" 
     xmlns:viewModel="clr-namespace:MyStuff.ViewModel;assembly=MyStuff.ViewModel" 
     xmlns:sys="clr-namespace:System;assembly=mscorlib">  
<UserControl.Resources> 
    <ObjectDataProvider x:Key="EnumDataProvider"        
         MethodName="GetValues"        
         ObjectType="{x:Type sys:Enum}"> 
     <ObjectDataProvider.MethodParameters> 

<!--None of these work at all, I'm lost :(I've tried variations of these: --> 
<!--<viewModel:BatchInfoViewModel></viewModel:BatchInfoViewModel> 
<x:Type TypeName="viewModel:TimeFrame"/> 
<x:Type TypeName="BatchInfoViewModel:TimeFrame"/>--> 


     </ObjectDataProvider.MethodParameters> 
    </ObjectDataProvider> 

它无法找到类型并会抛出异常。

回答

5

您有一个嵌套在类中的枚举,将枚举放置在名称空间中,在任何类之外并使用viewModel:TimeFrame

(我测试,你可以在枚举使用x:Static+拼接语法,但它不会出现在这里申请)

+0

配售枚举在命名空间中,任何类之外的地区的车票。谢谢 ! – cjsmith

+0

@cjsmith:很高兴帮助,只是测试了我以前的建议,但它不适用于此。 –