c# - How to write a custom dependecy property and data bind to custom type? -
i have project in winrt environment trying extend functionality of standard gridview control extending it. goal change selecteditems behaviour of gridview.
public class mygridview : gridview { /// <summary> /// replacement of selecteditems /// </summary> public iobservablevector<object> appitems { { return getvalue(appselecteditemsproperty) iobservablevector<object>; } set { setvalue(appselecteditemsproperty, value); appitems.vectorchanged += appselecteditemschanged; } } /// <summary> /// identifies appselecteditems dependency property. /// </summary> public static readonly dependencyproperty appselecteditemsproperty = dependencyproperty.register( "appitems", typeof(iobservablevector<object>), typeof(appgridview), new propertymetadata(null, appitemspropertycallback)); …. …. ... } in xaml file have following..
<xx ……. <appcontrols:appgridview appitems="{binding contactslistselecteditems, mode=twoway } }"> .… … </appcontrols:appgridview > ….. ……. /xx> the final piece of code mvvm class bound datacontext.
public class mymodel: basemodel { …… …….. /// <summary> /// not working /// </summary> private iobservablevector<contact> _contactslistselecteditems; public iobservablevector<contact> contactslistselecteditems { { return (iobservablevector<contact>)_contactslistselecteditems; } set { setproperty<iobservablevector<contact>>(ref _contactslistselecteditems, value); } } …. …. } i found implementation of iobservablevector here : https://gist.github.com/runceel/2437074
the data binding contactslistselecteditems not working giving following error:
error: cannot 'contactslistselecteditems' value (type 'object') type 'consius.activework.pages.contactpage.contactpageviewmodel, consius.activework, version=1.0.0.0, culture=neutral, publickeytoken=null'. bindingexpression: path='contactslistselecteditems' dataitem='consius.activework.pages.contactpage.contactpageviewmodel, consius.activework, version=1.0.0.0, culture=neutral, publickeytoken=null'; target element 'consius.activework.controls.appgridview' (name='contactslist'); target property 'appitems' (type 'iobservablevector`1<object>'). if change type of contactslistselecteditems to:
iobservablevector<object> it works well.
this not acceptable solution me, writing mvvm class using class object.
is there out there can give me hint whats wrong?
have tried observablecollection instead of iobservablevector , custom implementation found?
Comments
Post a Comment