Trying to change the standard button selection.

ControlTemplate ct = new ControlTemplate(); var t = new Trigger(); ct.Triggers = t.Property 

I know that Property needs to be changed, but I don’t know what to write next Anyone tell me?

    1 answer 1

    You can define a style in App.xaml and get it using

     MyButton.Style = FindResource("MyButtonStyle") as Style; 

    An example of a style to change the default button selection

     <Application.Resources> <Style x:Key="MyButtonStyle" TargetType="{x:Type Button}"> <Setter Property="Background" Value="LightGreen"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/> </Border> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="Orange"/> </Trigger> <Trigger Property="IsPressed" Value="True"> <Setter Property="Background" Value="LightSkyBlue"/> </Trigger> </Style.Triggers> </Style> </Application.Resources> 

    Here you need to work on the overridden Template buttons.

    • Yes, I know how to do this in xaml. My buttons are programmatically created under certain conditions - andrew
    • You can refer to the resource . I correct my answer. So fit or anyway not? - Andrey K.
    • Yes, that is fine - andrew