I'd like to create a customized checkbox that behaves exactly like StackOverflow's "accept answer" checkbox:
alt text http://sstatic.net/so/img/vote-accepted-on.png
alt text http://sstatic.net/so/img/vote-accepted.png
That is, I simply want to display a single image when checked, and a single different im开发者_运维问答age 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?
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.
精彩评论