WPF uses the Trigger system of XAML to implement a tri-state button

Source: Internet
Author: User

With WPF's Trigger system, you can also simply implement a tri-state button using only xmal. Declare the style of the button in the Resource of window or UserControl and add the trigger function. Use the time directly in the button to make a copy of the style can be, nonsense not much to say, directly on the code:

<UserControl.Resources> <style x:key= "Threestatebutton" targettype= "{x:type button}" > <se Tter property= "Snapstodevicepixels" value= "true"/> <setter property= "Overridesdefaultstyle" Value= "true"/ > <setter property= "Template" > <Setter.Value> <controltempl                            Ate targettype= "{x:type button}" > <stackpanel orientation= "Horizontal" >                        <image name= "ImgBtnBg3" source= "Skins/default/action_normal.png"/>                            </StackPanel> <ControlTemplate.Triggers>                                         <trigger property= "IsMouseOver" value= "True" > <setter property= "Source" Value= "Skins/default/action_selected.png" Targetnam      E= "ImgBtnBg3"/>                      </Trigger> <trigger property= "ispressed" value= "True" > <setter property= "Source" value= "Skins/default/action_ Active.png "targetname=" ImgBtnBg3 "/> </trigger&gt                            ;                                         <trigger property= "isenabled" value= "False" > <setter property= "Source" Value= "Skins/default/action_normal.png" Targetname= "I                    MgBtnBg3 "/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </style&gt    ; </UserControl.Resources>

Referenced in the button when used:

<button x:name= "m_btn" content= "button" horizontalalignment= "Center" width= "All" height= "60"
Verticalalignment= "Center" style= "{StaticResource Threestatebutton}"/>

WPF uses the Trigger system of XAML to implement a tri-state button

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.