c# - wpf binding not updating -
using mvvm, have view contains dependencyproperty, , listbox bound viewmodel:
public static readonly dependencyproperty selectedserverproperty = dependencyproperty.register("selectedserver",typeof(object), typeof(serverview), new frameworkpropertymetadata(test)); public object selectedserver { { return getvalue(selectedserverproperty); } set { setvalue(selectedserverproperty, value); } } public serverview() { setbinding(selectedserverproperty, "selectedserver"); initializecomponent(); } public static void test(dependancyobject sender, dependancypropertychangedeventargs e) { ... }
xaml:
<listbox itemssource="{binding servers}" displaymemberpath="name" selecteditem="{binding selectedserver}" />
and viewmodel implements inotifypropertychanged:
servermodel _selectedserver; public servermodel selectedserver { { return _selectedserver; } set { _selectedserver = value; raisepropertychanged("selectedserver"); } }
when select item in list, viewmodel updated, dependencyproperty in view stays same. test event created not triggered. doing wrong?
i think setbinding
trying bind property
defined in view , not vm. try using syntax
setbinding(selectedserverproperty, new binding("selectedserver"));
this try bind selectedserver
property in vm (datacontext
of view).here link msdn you.
Comments
Post a Comment