简体   繁体   中英

Propertychanged Template10 Class

The propertychanged trigger in a viewmodel of a UWP app with Template10 is triggered by by the following way:

public var Thing{ get { return thing; } set { Set(ref thing, value); } }

The Set function is placed in the class bindableBase.

How can I use this same function in a Usercontrol?

I tried the folowing, but that didn't work:

BindableBase x;

var foo;
public var Foo{ get { return foo; } set { x.Set(ref foo, value); } }

you don't use in that fashion you use with a viewmodel for example if the Page you place the usercontrol would have a property associated with populating the fields of the usercontrol part of the viewmodel that is bound to the DataContext of the Page. I think you need to review MVVM. Or the viewmodel could be the DataContext of the userControl in question.

When creating a UserControl you'll want to use a DependencyProperty to create bindable properties. It's required to make them behave as expected when using the UserControl inside of an other control (like a Page ). DependencyProperties are defined like this:

    public int MyProperty
    {
        get { return (int)GetValue(MyPropertyProperty); }
        set { SetValue(MyPropertyProperty, value); }
    }

    // Using a DependencyProperty as the backing store for MyProperty.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty MyPropertyProperty =
        DependencyProperty.Register("MyProperty", typeof(int), typeof(ownerclass), new PropertyMetadata(0));

They're most easily created using the propdp snippet in Visual Studio.

I recommend giving this MVA course a look (especially the first lesson) on how to create custom controls

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM