Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is There any way for style for specific control by name in wpf

Tags:

styles

wpf

Set control color via resource.

in resource file:

<style TargetType="{x:Name button1}">
      <setter Property="ColorBrush" Value="Red"/>
</style>
<Window .... >
    <Button Name="Button1" Content="Test Button" />
</Window>

like css in html

 <style>
       #controlID
       {
         color:red;
       }
    </style>
<body>
      <input id="button1" type="button" value="test button" />
</body>
like image 875
mehdi Avatar asked Aug 10 '15 10:08

mehdi


1 Answers

Define a Style like this in window.resources

<Window.Resources>
    <Style x:Key="btnStyleRed" TargetType="Button">
                <Setter Property="Background" Value="Red"/>
            </Style>
 </Window.Resources>

and use this style only on those button to which you want to apply particular style

<Button x:Name="btnLogin" Style="{StaticResource btnStyleRed}" Content="Login" Width="75" />
like image 58
shreesha Avatar answered Nov 15 '22 07:11

shreesha