多次使用相同的 FrameworkPropertyMetaData
我有 3 个依赖属性和一个 FrameworkPropertyMetadata,当我尝试在多个 DP 上使用元数据时,我遇到了崩溃。我不想有 3 个重复的元数据,有办法解决这个问题吗?
static FrameworkPropertyMetadata propertyMetaData = new FrameworkPropertyMetadata("My Control", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault);
public static readonly DependencyProperty Property_A = DependencyProperty.Register("Property_A", typeof(string), typeof(MyControl), propertyMetaData);
public static readonly DependencyProperty Property_B = DependencyProperty.Register("Property_B", typeof(string), typeof(MyControl), propertyMetaData);
public static readonly DependencyProperty Property_C = DependencyProperty.Register("Property_C", typeof(string), typeof(MyControl), propertyMetaData);
我是否需要为每个属性声明单独的元数据,还是可以使用相同的元数据?
谢谢, 埃蒙
I have 3 dependancy Properties and a FrameworkPropertyMetadata, I get a crash when I try to use the metadata on more than one DP. I dont want to have 3 duplicates of the metadatam is there a way around this.
static FrameworkPropertyMetadata propertyMetaData = new FrameworkPropertyMetadata("My Control", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault);
public static readonly DependencyProperty Property_A = DependencyProperty.Register("Property_A", typeof(string), typeof(MyControl), propertyMetaData);
public static readonly DependencyProperty Property_B = DependencyProperty.Register("Property_B", typeof(string), typeof(MyControl), propertyMetaData);
public static readonly DependencyProperty Property_C = DependencyProperty.Register("Property_C", typeof(string), typeof(MyControl), propertyMetaData);
Do I need to declare a seperate metadata for each property or can I use the same one?
Thanks,
Eamonn
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想避免代码重复(这看起来很合理),您可以编写类似于以下的简单实用方法:
然后使用它:
如果我正在解释显而易见的事情,请原谅。
If you want to avoid code repeating (which seem reasonable), you can write simple utility method similar to:
And then use it:
Excuse me if I'm explaining obvious things.
您需要为每一项声明一个新的。
You need to declare a new one for each.