Binding issues with Appbartogglebutton in Windows Phone 8.1

Source: Internet
Author: User

In WP8.1, the app bar button already supports binding, and it provides a Appbartogglebutton type, which is the equivalent of a toggle button that has a property ischecked that the tag is selected.

So take it for granted, bind the ischecked to a property, and set it to two-way binding. The result is that it does not work, and when the property changes, the IsChecked property of the Appbartogglebutton cannot be notified of changes.

Then write an extended property to do this, the code is as follows:

     Public classtogglebuttonproperties { Public Static ReadOnlyDependencyProperty Ischeckedproperty =dependencyproperty.registerattached ("IsChecked",                                          typeof(BOOL),                                          typeof(togglebuttonproperties),NewPropertyMetadata (false, OnChanged));  Public Static BOOLgetischecked (DependencyObject obj) {return(BOOL) obj.        GetValue (Ischeckedproperty); }         Public Static voidsetischecked (DependencyObject obj,BOOLvalue) {obj.        SetValue (ischeckedproperty, value); }        Private Static voidOnChanged (DependencyObject o, DependencyPropertyChangedEventArgs args) { ToggleButton TB= O asToggleButton; if(NULL!=TB) TB. IsChecked= (BOOL) args.        NewValue; }    }

This is used when binding:

            <appbartogglebutton icon="Comment " label=" comments " controlhelper:togglebuttonproperties.ischecked="{Binding isshowcomments}" command= " {Binding commandnavtocomments} " />

This allows you to synchronize the changes in the properties.

Binding issues with Appbartogglebutton in Windows Phone 8.1

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.