Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting value from style setter property in xaml

Tags:

wpf

How can I get the value of style setter property in xaml?

For example, I have next style:

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

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

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

I need this because I haven't access to TextBox style..

like image 385
Chepene Avatar asked Jan 13 '23 06:01

Chepene


1 Answers

If you can't modify TextBox style, you could do this work-around (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 style's setter for background.

like image 115
lisp Avatar answered Jan 22 '23 08:01

lisp