views:

169

answers:

1

I'd like to create a customized checkbox that behaves exactly like StackOverflow's "accept answer" checkbox:

alt text

alt text

That is, I simply want to display a single image when checked, and a single different image when unchecked. I don't care about indeterminate state.

I'm a bit of a newbie when it comes to WPF ControlTemplates, so I'm having trouble customizing the CheckbBox's ControlTemplate to show these images when checked/unchecked. Can someone point me in the right direction?

+4  A: 

Here's 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 pretty rudimentary because it doesn't respect things like margin and padding, but those probably aren't essential for you right now. The key thing is the use of the Trigger and Setter to change the image source when IsChecked is true -- you should be able to build up from there.

itowlson
Thanks! I'll give that a shot.
Judah Himango
That worked great. I've accepted your answer. Thanks again.
Judah Himango