c# - Use Dependency Property to pass a callback method -


i using jarloo's calendar control in order display calendar in wpf software. needs, added each day contains list of items, lets list<item> items.

the jarloo calendar second project within main visual studio solution. using control way :

<jarloo:calendar daychangedcallback="{binding daychangedeventhandler}"/> 

as can see, wish pass method main project calendar's project can, within calendar's constructor, add method eventhandler of daychanged event.

however, item received through dependency null...

in calendar code, dependency property defined :

public static readonly dependencyproperty daychangedcallbackproperty = dependencyproperty.register("daychangedcallback", typeof(eventhandler<daychangedeventargs>), typeof(calendar)); 

my "daychangedeventhandler" defined as

public eventhandler<daychangedeventargs> daychangedhandler { get; set; } void daychanged(object o, daychangedeventargs e) { }  // set way daychangedhandler property can bind on view daychangedhandler = new eventhandler<daychangedeventargs>(daychanged); 

does has hint me?

thanks lot :) .x

here example regarding non-static field issue:

public partial class mainwindow : window {    public bool ischecked    {        { return (bool)getvalue(ischeckedproperty); }        set { setvalue(ischeckedproperty, value); }    }  // using dependencyproperty backing store ischecked.  enables animation, styling, binding, etc...    public static readonly dependencyproperty ischeckedproperty =     dependencyproperty.register("ischecked", typeof(bool), typeof(mainwindow), new propertymetadata(false, new propertychangedcallback(propertychanged)));      private static void propertychanged(dependencyobject obj, dependencypropertychangedeventargs e)    {        mainwindow localwindow = (mainwindow)obj;        console.writeline(localwindow.teststring);     }     public string teststring { get; set; }      public mainwindow()     {        initializecomponent();         teststring = "test";        this.datacontext = this;     } } 

and here xaml test it:

<checkbox content="case sensitive" ischecked="{binding ischecked}"/> 

when property changed, callback called , in thix example, can access non static teststring property.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -