[Note for custom attached property usage in Uwp]xaml

Source: Internet
Author: User

---restore content starts---

A small note of essays, Welcome to correct me

When you do WVVM on the UWP platform, you want to define a custom command for the SelectionChanged event of the ListBox, so you use the way you customize attached properties. But finally, the custom attached property Selectionchangedcommand is written, but does not know how to use it in XAML.

My custom attributes are as follows:

namespaceselectionchangedcommand.services{ Public Static classSelectionchangedbehavior { Public Static ReadOnlyDependencyProperty Selectionchangedcommandproperty = Dependencyproperty.register ("Selectionchangedcommand",typeof(ICommand),typeof(Selectionchangedbehavior),NewPropertyMetadata (NULL, Selectionchangedpropertycallback));  Public Static voidSetselectionchangedcommand (UIElement element, ICommand value) {element.        SetValue (selectionchangedcommandproperty, value); }         Public StaticICommand Getselectionchangedcommand (UIElement element) {return(ICommand) element.        GetValue (Selectionchangedcommandproperty); }         Public Static voidSelectionchangedpropertycallback (DependencyObject D, DependencyPropertyChangedEventArgs e) {Listbo X ListBox=(ListBox) D; Listbox.selectionchanged+=listbox_selectionchanged; }        Private Static voidListbox_selectionchanged (Objectsender, SelectionChangedEventArgs e) {ListBox ListBox=(ListBox) sender; Getselectionchangedcommand (ListBox).        Execute (Listbox.selecteditem); }    }}

So Baidu, see in WPF is the following wording:

Xmlns:aqua= "Clr-namespace:aquariumobjects;assembly=aquariumlibrary"

So I imitated the following code.

Xmlns:my= "Clr-namespace:selectionchangedcommand.services;assembly=selectionchangedcommand"

where "Selectionchangedcommand" is the name of my assembly.

And then, in a ListBox, the following references are made

<my:SelectionChangedBehavior.SelectionChangedCommand= "{Binding Selectionchangedcommand}"></ListBox>

The results suggest that I have an unknown attachable member "Selectionchangedbehavior.selectionchangedcommand", so I changed the namespace above to

Xmlns:my= "Using:SelectionChangedCommand.Services"

The result will be.

So what's the difference between Clr-namespace and using?

Currently found on the Internet: Silvelight is: Clr-namespace. The WINDOWS8 is changed into a using.

[Note for custom attached property usage in Uwp]xaml

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.