Silverlight 4依赖项属性的默认值,使用另一个依赖项属性的默认值

时间:2011-10-05 12:48:10

标签: silverlight silverlight-4.0 dependency-properties default-value

我试图通过使用:

使用textblock属性的默认值作为控件
 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

没有给我正确的默认值,或者我没有正确使用它。任何帮助是极大的赞赏。谢谢你提前。

1 个答案:

答案 0 :(得分:2)

您传递给GetMetaData的类型不是属性类型,而是所有者类型。因此你应该使用: -

 TextBlock.FontFamilyProperty.GetMetadata(typeof(TextBlock)).DefaultValue
相关问题