Getting value from set setter property in xaml

How can I get the value of the setterter property in xaml?

For example, I have the following style:

<Style TargetType="TextBox"> <Setter Property="Background" Value="YellowGreen" /> </Style> 

How can I get the value of the Background property from the default style in a TextBox?

 <Style TargetType="Button"> <Setter Property="Background" Value="{Binding ???}" /> </Style> 

I need this because I do not have access to TextBox style ..

+4
source share
2 answers

If you cannot change the style of the TextBox, you can do this work (tested, works):

 <TextBox x:Key="DefaultTextBox" /> <Style TargetType="Button"> <Setter Property="Background" Value="{Binding Source={StaticResource DefaultTextBox}, Path=Background}" /> </Style> 

You cannot bind in xaml to the setter style for the background.

+5
source

You must reorganize your XAML:

 <SolidColorBrush x:Key="BackgroundBrush" Color="YellowGreen" /> <Style TargetType="TextBox"> <Setter Property="Background" Value="{StaticResource BackgroundBrush}" /> </Style> <Style TargetType="Button"> <Setter Property="Background" Value="{StaticResource BackgroundBrush}" /> </Style> 

Bindings hinder performance and are not designed for this type of action.

+3
source

Source: https://habr.com/ru/post/1483340/


All Articles