silverlightsilverlight-4.0dependency-propertiesdefault-value

Silverlight 4 default value for dependency property using the default value of another dependency property


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.


Solution

  • The type you pass to GetMetaData is the not the property type, its the owner type. Hence you should be using:-

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