I am working on a UserControl and within this I have created some Dependency Properties in order to set a Header Text and Font however when I try to create one for FontSize it doesn’t work.
My Dependency Properties code for Font and FontSize are below.
Set Font (Working)
public FontFamily LeftHeaderFontFamily
{
get { return (FontFamily)GetValue(LeftHeaderFontFamilyProperty); }
set { SetValue(LeftHeaderFontFamilyProperty, value); }
}
public static readonly DependencyProperty LeftHeaderFontFamilyProperty =
DependencyProperty.Register("LeftHeaderFontFamily", typeof(FontFamily), typeof(BaseView),
new PropertyMetadata(new FontFamily("Microsoft Sans Serif"), new PropertyChangedCallback(LeftHeaderFontChanged)));
private static void LeftHeaderFontChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
BaseView leftHeaderFont = d as BaseView;
leftHeaderFont.LeftHeaderFontChanged(e);
}PropertyCh
private void LeftHeaderFontChanged(DependencyPropertyChangedEventArgs e)
{
LeftHeaderTextBlock.FontFamily = LeftHeaderFontFamily;
}
Set FontSize (Not Working)
public double LeftHeaderFontSize
{
get { return (double)GetValue(LeftHeaderFontSizeProperty); }
set { SetValue(LeftHeaderFontSizeProperty, value); }
}
public static readonly DependencyProperty LeftHeaderFontSizeProperty =
DependencyProperty.Register("LeftHeaderFontSize", typeof(double), typeof(ViewBase),
new PropertyMetadata(12D, new PropertyChangedCallback(LeftHeaderFontSizeChanged)));
private static void LeftHeaderFontSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
BaseView leftHeaderFontSize = d as BaseView;
leftHeaderFontSize.LeftHeaderFontSizeChanged(e);
}
private void LeftHeaderFontSizeChanged(DependencyPropertyChangedEventArgs e)
{
LeftHeaderTextBlock.FontSize = LeftHeaderFontSize;
}
The intention is that the Header will update at Design Time, however the FontSize Dependency Property doesn't work at all. I can make it work if I bind the control to the Dependency Property without the PropertyChangedCallback but this understandably doesn't update at DesignTime.
What am I doing wrong. Any assistance would be much appreciated.