Is there a way to style for specific control by name in wpf

Set control color via resource.

in the resource file:

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

      

as css in html

 <style>
       #controlID
       {
         color:red;
       }
    </style>
<body>
      <input id="button1" type="button" value="test button" />
</body>

      

+3


source to share


1 answer


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 only use this style on the button to which you want to apply a special style

<Button x:Name="btnLogin" Style="{StaticResource btnStyleRed}" Content="Login" Width="75" />

      

+3


source







All Articles