Rosario
Rosario

Reputation: 21

Change the control property globally in wpf

I have a back button which is copied almost to all the Controls in my application.

I have set the styles and properties of the button on each individual control (usercontrol)

Now I want to change the text property of the button of all the control (usercontrol).

I don't want to go and change the property of each control.

Please help me setting a global property which sets the property in one place.

Upvotes: 0

Views: 848

Answers (2)

DeshDeep Singh
DeshDeep Singh

Reputation: 1853

<Style TargetType="{x:Type Button}">
            <Setter Property="Text" Value="{Binding text}" />
            <Setter Property="...." Value="{Binding ....}"/>
        </Style>

Add this to App.xaml file as you want it to be global style for all your user controls.

Upvotes: 1

Carbine
Carbine

Reputation: 7903

Since the style is common to all pages. Create the style without a key/name, just the target type would do.

<Style TargetType="{x:Type Button}">

Then do either of the following -

  • Add it to the App.XAML for visibility throughout the app
  • Better approach would be to define a resource dictionary file and import it, wherever you need it.

Upvotes: 2

Related Questions