c# - How to propagate PropertyChanged changes in DependencyProperty -


i have class implements inotifypropertychanged. instance of class declared dependencyproperty in window, e.g.,

    public imyclass myclass     {         { return (imyclass)getvalue(myclassproperty); }         set { setvalue(myclassproperty, value); }     }     public static readonly dependencyproperty myclassproperty=         dependencyproperty.register("myclass", typeof(imyclass), typeof(mainwindow), new uipropertymetadata(null)); 

in xaml, have element bound class using

text="{binding myclass, converter={staticresource someconverter}} 

whenever change property in myclass, someconverter triggered. however, happens when swap out myclass. there way tie dependencyproperty updates myclass propertychanged?

update. in spirit of aresavatar's solution, here's have far. issue remaining how call invalidateproperty (without having myclass track it...)

    public imyclass myclass     {         { return (imyclass)getvalue(myclassproperty); }         set { setvalue(myclassproperty, value); }     }     public static readonly dependencyproperty myclassproperty =         dependencyproperty.register("myclass", typeof(imyclass), typeof(mainwindow),         new uipropertymetadata(null, new propertychangedcallback(onmyclasschanged)));      private static void onmyclasschanged(dependencyobject d, dependencypropertychangedeventargs e)     {         if (e.oldvalue != null)         {             ((imyclass)e.oldvalue).propertychanged -= ((mainwindow)d).myclass_propertychanged;         }          if (e.newvalue != null)         {             ((imyclass)e.newvalue).propertychanged += ((mainwindow)d).myclass_propertychanged;         }     }      private void myclass_propertychanged(object sender, system.componentmodel.propertychangedeventargs e)     {         this.invalidateproperty(myclassproperty);  <----- still not refresh binding, called.     } 

converters should not more work simple conversions, question sounds converter uses lot of properties of object create combined value. use multibinding instead hooks different properties on object need, way multivalueconverter on multibinding fire if of properties change.

further, since seem create text might able away without using converter @ stringformat might enough.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -