Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在WPF中将枚举用作依赖项属性_C#_Wpf_Enums_Custom Controls_Dependency Properties - Fatal编程技术网

C# 在WPF中将枚举用作依赖项属性

C# 在WPF中将枚举用作依赖项属性,c#,wpf,enums,custom-controls,dependency-properties,C#,Wpf,Enums,Custom Controls,Dependency Properties,我尝试将枚举类型用作自定义控件中的依赖项属性,但始终出现错误: public enum PriceCategories { First = 1, Second = 2, Third = 3, Fourth = 4, Fifth = 5, Sixth = 6 } public static readonly DependencyProperty PriceCatProperty

我尝试将枚举类型用作自定义控件中的依赖项属性,但始终出现错误:

public enum PriceCategories
    {
        First = 1,
        Second = 2,
        Third = 3,
        Fourth = 4,
        Fifth = 5,
        Sixth = 6
    }
    public static readonly DependencyProperty PriceCatProperty =
DependencyProperty.Register("PriceCat", typeof(PriceCategories), typeof(CustControl), new PropertyMetadata(PriceCategories.First));
};

    public PriceCategories PriceCat  // here I get an error "Expected class, delegate, enum, interface or struct"
    {
        get { return (PriceCategories)GetValue(PriceCatProperty); }
        set { SetValue(PriceCatProperty, value); }
    }

请看。哪里有错误?

您的DP未在类的范围内声明。在DP声明之后,似乎有一个额外的右大括号

public enum PriceCategories
{
  // ...
}
public static readonly DependencyProperty PriceCatProperty =
  DependencyProperty.Register("PriceCat", typeof(PriceCategories),
  typeof(CustControl),  new PropertyMetadata(PriceCategories.First));
};  // <-- this is probably closing the containing class
公共枚举价格类别
{
// ...
}
公共静态只读从属属性PriceCatProperty=
从属财产登记簿(“价格类别”),类型(价格类别),
typeof(CustControl),新的PropertyMetadata(PriceCategories.First));

}; // 哦,是的,就是这个支架。非常感谢。