WPF flag, such as the StackOverflow accepted response flag

I would like to create a custom flag that behaves exactly the same as the Accept Answer flag in StackOverflow:

alt text http://sstatic.net/so/img/vote-accepted-on.png

alt text http://sstatic.net/so/img/vote-accepted.png

That is, I just want to display one image when checking and one other image when unchecking. I don't care about the uncertain state.

I'm a little new when it comes to WPF ControlTemplates, so I'm having trouble setting up a CheckbBox ControlTemplate to show these images when they are checked / unchecked. Can someone point me in the right direction?

+3
source share
1 answer

Here is a simple version:

<ControlTemplate TargetType="CheckBox">
  <Image Name="TickImage" Source="HollowTick.png" />
  <ControlTemplate.Triggers>
    <Trigger Property="IsChecked" Value="True">
      <Setter TargetName="TickImage" Property="Source" Value="FilledTick.png" />
    </Trigger>
  </ControlTemplate.Triggers>
</ControlTemplate>

This is rather rudimentary, because he does not respect such things as margin and indentation, but they are probably not important to you now. The main thing is to use a trigger and setter to change the image source, when IsChecked is true - you should be able to build from there.

+15
source

Source: https://habr.com/ru/post/1740070/


All Articles