【问题标题】:Silverlight 4 default value for dependency property using the default value of another dependency propertySilverlight 4 依赖属性的默认值使用另一个依赖属性的默认值
【发布时间】:2011-12-01 11:16:00
【问题描述】:

我正在尝试通过以下方式将文本块属性的默认值用于控件:

 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

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

【问题讨论】:

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


    【解决方案1】:

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

     TextBlock.FontFamilyProperty.GetMetadata(typeof(TextBlock)).DefaultValue
    

    【讨论】:

      猜你喜欢
      • 2011-08-19
      • 1970-01-01
      • 2019-07-26
      • 1970-01-01
      • 2018-06-07
      • 1970-01-01
      • 1970-01-01
      • 2015-10-17
      相关资源
      最近更新 更多