gpt4 book ai didi

c# - 在 WPF 中使用枚举作为依赖属性

转载 作者:太空狗 更新时间:2023-10-29 20:09:00 26 4
gpt4 key购买 nike

我尝试在我的自定义控件中使用枚举类型作为依赖属性,但总是出现错误:

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

关于c# - 在 WPF 中使用枚举作为依赖属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1857967/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com