I have a User Control that is passing multiple properties to an internal textblock, like so:
<UserControl x:Name="Root">
<Grid>
<TextBlock x:Name="ContentBlock"
TextWrapping="WrapWholeWords"
FontFamily="{Binding FontFamily}"
FontWeight="{Binding FontWeight}"
Text="{Binding Text}"
LineHeight="{Binding LineHeight}"
Foreground="{Binding Foreground}"
/>
</Grid>
</UserControl>
And in the user control I have the following:
public CustomTextBlock()
{
this.InitializeComponent();
(this.Content as FrameworkElement).DataContext = this;
}
public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text",
typeof(string), typeof(CustomTextBlock), null);
public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValueDp(TextProperty, value); }
}
public event PropertyChangedEventHandler PropertyChanged;
public void SetValueDp(DependencyProperty property, object value, [CallerMemberName]string propertyName = null)
{
SetValue(property, value);
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
Where I'm using this control I'm binding to a few of those properties like so:
<controls:CustomTextBlock Text="{Binding Question.Text}"
FontSize="30"
MaxHeight="130"
Margin="0, 0, 10, 0"/>
However, the text isn't being passed through the binding into the control properly. Everything I've seen says this should work, but it's not. Any ideas what's causing my text not to be passed through to the dependency property?