Windows 8 Metro style development (9)-interactive (behavior and eventtrigger)

Source: Internet
Author: User

Those who have developed Windows Phone or Silverlight must know that there is an interactive DLL that can add behavior and eventtrigger to the element. However, the corresponding class libraries are not officially provided in Windows 8, but we can't do it if it's not equal. In fact, we can develop an interactive class library by ourselves. This class library is already included in my open-source class library. Next I will introduce how to use eventtrigger to bind events to elements in the template.

As you know, you cannot directly add events to controls in templates.CodeAfter obtaining the control, add it as code. However, this method is very troublesome. The trouble is that you need to traverse the tree and obtain the control in the tree. It is not convenient to use the XAML code in the template to register events. Eventtrigger is dedicated to this purpose. You only need to specify the event name for eventtrigger, and then specify the callback (icommand) when the event is triggered. The implementation code is as follows:

         <  Controltemplate  X: Key  = "Contentcontroltemplate"  Targettype  = "Contentcontrol"  >              < Grid  >                  <  Button  Content  = "Click me"  >                      <  I: interaction. triggers  >                          <  I: eventtrigger  Eventname  = "Click"  Command  =" {Binding clickcommand, source = {staticresource mainpageviewmodel }}  "   />                      </  I: interaction. triggers  >                  </  Button  >              </  Grid  >          </  Controltemplate  > 

Eventname is the name of the specified event. I have specified click here. You can replace it with any event name you want.

The interactive usage here is no different from that in Windows Phone and Silverlight.

You can use behavior to add a behavior for a widget. Google can be used if you are not familiar with it.

Source code download, including the Library source code

 

Related Article

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.