c# - Silverlight: When is a dependency property available? -
i setting dependency property in xaml (silverlight 4):
<my:topsearchbar x:name="topsearchbar" grid.row="0" navigator="{binding elementname=navigationframe}" horizontalalignment="stretch" verticalalignment="top" />
i need register navigation events of navigationframe
. however, following fails null pointer exception:
public topsearchbar() { // required initialize variables initializecomponent(); loaded += new routedeventhandler(topsearchbar_loaded); } void topsearchbar_loaded(object sender, routedeventargs e) { // navigator null navigator.navigated += new navigatedeventhandler(navigated); }
when right time register these event handlers? tried doing in property setter, breakpoint never hit:
public frame navigator { { return getvalue(navigatorproperty) frame; } set { setvalue(navigatorproperty, value); } }
bindings not use navigator
property. instead, binding class accesses navigatorproperty
field, of type dependencyproperty
, directly, , sets value.
in code behind, can overridemetadata on navigatorproperty object. create propertymetadata includes propertychangedcallback, , add event handler there. aware, overridemetadata works on instances of type specify, specify lowest 1 need (topsearchbar, probably), , careful.
Comments
Post a Comment