I would like to bind my DependencyProperty to a label of my custom button.
Here is my DependencyProperty:
public static readonly DependencyProperty ButtonTextProperty = DependencyProperty.Register("ButtonText", typeof(string), typeof(MainMenuButton));
public string ButtonText
{
get { return (string)GetValue(ButtonTextProperty); }
set { SetValue(ButtonTextProperty, value); }
}
And here is my attempt to bind the value to the label:
<TextBlock x:Name="lblButtonText" Margin="16,45.2465" TextWrapping="Wrap" Text="{Binding RelativeSource={RelativeSource Mode=Self}, Path=ButtonText}" VerticalAlignment="Center" TextAlignment="Right" Foreground="White" FontSize="17.333" FontWeight="Bold" FontFamily="Segoe UI Semibold" Height="26.053"/>
This way of binding my DependencyProperties worked several times in other cases but I can’t figure out why it doesn’t work this time?
How can I solve this problem?
You are setting the source of your binding to
Self, andSelfis aTextBlock, andTextBlockdoes not have a property calledButtonTextYou’re probably looking to set the source of your binding to a
RelativeSourceof typeMyCustomButton