简体   繁体   中英

wpf button background change

I am trying to change the button color on click event.

This is my code:

 <Button Content="Start"
 Command="{Binding DataContext.StartCounterCommand, ElementName=dgTemplate1}"
 CommandParameter="{Binding SelectedItem, ElementName=dgTemplate1}" />

Use a style trigger on the pressed state, something like:

<Style x:Key="ButtonStyle" TargetType="{x:Type Button}">
    <Style.Triggers>
        <Trigger Property="IsPressed" Value="True">
            <Setter Property="Background" Value="Red" />
        </Trigger>
    </Style.Triggers>
</Style>

I dug up a good sample that is close here

If you are using MVVM them binding to a view model is also a good option as per @schlonzo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM