Monday 15 June 2015

c# - Dependency Property on a usercontrol that is bound to another VM -



c# - Dependency Property on a usercontrol that is bound to another VM -

i've run next problem: i'm creating on screen keyboard usercontrol has own viewmodel.

<usercontrol.datacontext> <binding source="{staticresource locator}" path="alphanumerickeyboard" /> </usercontrol.datacontext>

i'm attempting add together dependency property called keyboardalphamode can toggled other view models using usercontrol

public static readonly dependencyproperty keyboardalphamodeproperty = dependencyproperty.register("keyboardalphamode", typeof(uikeyboardalphamode), typeof(alphanumerickeyboardview), new frameworkpropertymetadata(uikeyboardalphamode.lowercase, new propertychangedcallback(keyboardalphamodecallback))); private static void keyboardalphamodecallback(dependencyobject d, dependencypropertychangedeventargs e){ ... }

but, when effort bind property view, callback never fired ..

<k:alphanumerickeyboardview x:name="alphanumerickeyboard" keyboardalphamode="{binding keyboardalphamode, updatesourcetrigger=propertychanged}"> </k:alphanumerickeyboardview>

what missing here? setter? trigger?

or thought, can usercontrol has dependency bound viewmodel? or have bound itself?

edit - 10/10/2014 @ 1:31pm after rethinking entire solution came next scenario problem. binded dependency property view's viewmodel , allow viewmodels interact each other instead having other viewmodel talking specific view ...

here's code ..

binding alphamodebinding = new binding("keyboardalphamode") { mode = bindingmode.twoway, targetnullvalue = uikeyboardalphamode.lowercase, fallbackvalue = uikeyboardalphamode.lowercase }; this.setbinding(keyboardalphamodeproperty, alphamodebinding);

i made dependency property protected no 1 else can access it. unless there improve way track property changes, i'm sticking now.

again, not sure best solution gets job done.

try mode=twoway on binding.

c# wpf xaml mvvm

No comments:

Post a Comment