wpf-a custom checkbox

Source: Internet
Author: User

The original checkbox style in WPF is simple and sometimes does not apply to the awesome interface of WPF.

This section describes how to design a good-looking checkbox that matches your business needs (following the checkbox style in the wpf-custom listbox)

The checkbox style is as follows:

<style x:key= "Checkboxstyle" targettype= "{x:type CheckBox}" >

<setter property= "Snapstodevicepixels"
value= "true"/>
<setter property= "Overridesdefaultstyle"
value= "False"/>
<setter property= "FocusVisualStyle"
value= "{DynamicResource checkboxfocusvisual}"/>

<setter property= "Template" >
<Setter.Value>
<ControlTemplate>
<BulletDecorator>
<BulletDecorator.Bullet>
<grid height= "{TemplateBinding Height}" width= "{TemplateBinding Width}" >
<border x:name= "Border" >
<rectangle fill= "DodgerBlue" radiusy= "5" radiusx= "5" ></Rectangle>
</Border>
<grid x:name= "Checkedmark" >
<path visibility= "Visible" width= "height=" "snapstodevicepixels=" False "
strokethickness= "2" data= "m1,6 l7,12" >
<Path.Stroke>
<solidcolorbrush color= "white"/>
</Path.Stroke>
</Path>
<path visibility= "Visible" width= "height="
snapstodevicepixels= "False" strokethickness= "2" data= "m6,12 l14,2" >
<Path.Stroke>
<solidcolorbrush color= "white"/>
</Path.Stroke>
</Path>
</Grid>
</Grid>
</BulletDecorator.Bullet>
<VisualStateManager.VisualStateGroups>
<visualstategroup x:name= "Checkstates" >
<visualstate x:name= "Checked" >
<Storyboard>
<objectanimationusingkeyframes storyboard.targetproperty= "Visibility"
storyboard.targetname= "Checkedmark" >
<discreteobjectkeyframe keytime= "0"
value= "{x:static visibility.visible}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<visualstate x:name= "Unchecked" >
<Storyboard>
<objectanimationusingkeyframes storyboard.targetproperty= "Visibility"
storyboard.targetname= "Checkedmark" >
<discreteobjectkeyframe keytime= "0"
value= "{x:static visibility.collapsed}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<visualstate x:name= "indeterminate" >
<Storyboard>
<objectanimationusingkeyframes storyboard.targetproperty= "Visibility"
storyboard.targetname= "Checkedmark" >
<discreteobjectkeyframe keytime= "0"
value= "{x:static visibility.collapsed}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</BulletDecorator>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

The pattern mainly involves a checkbox template, the specific design ideas are as follows:

1, with a decorative control bulletdecorator as the root node

2, then the concrete content, uses the retangle to draw the square box with the rounded angle, sets the background

3, draw two lines, assembled into a √

4, add visual display, here with VisualStateManager to control. Of course, it's also possible to use common trigger trigger.

This style is well designed. Then apply to the actual checkbox:

<IsChecked= "True"  Height= "  Width= " Style =" {StaticResource Checkboxstyle} " ></ CheckBox >

Is it very simple ~ haha

wpf-a custom checkbox

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.