Silverlight 4 依赖属性的默认值使用另一个依赖属性的默认值
我尝试使用控件的文本块属性的默认值:
public static readonly DependencyProperty FontFamilyProperty = DependencyProperty.Register(
"FontFamily", typeof(FontFamily), typeof(IMTextBlock), new PropertyMetadata(TextBlock.TextProperty.GetMetadata(typeof(FontFamily)).DefaultValue));
我收到此错误:
The invocation of the constructor on type 'Common.Infrastructure.Controls.IMTextBlock' that matches the specified binding constraints threw an exception.
执行此操作的正确方法是什么?
TextBlock.TextProperty.GetMetadata(typeof(FontFamily)).DefaultValue
没有给我正确的默认值,或者可能我没有正确使用它。
I am trying to use the default value of the textblock's property for a control by using:
public static readonly DependencyProperty FontFamilyProperty = DependencyProperty.Register(
"FontFamily", typeof(FontFamily), typeof(IMTextBlock), new PropertyMetadata(TextBlock.TextProperty.GetMetadata(typeof(FontFamily)).DefaultValue));
I am getting this error:
The invocation of the constructor on type 'Common.Infrastructure.Controls.IMTextBlock' that matches the specified binding constraints threw an exception.
What is the right way to do this?
TextBlock.TextProperty.GetMetadata(typeof(FontFamily)).DefaultValue
is not getting me the correct default value, or maybe I am not using it correctly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您传递给
GetMetaData
的类型不是属性类型,而是所有者类型。因此你应该使用:-The type you pass to
GetMetaData
is the not the property type, its the owner type. Hence you should be using:-