开发者

Help converting NotifyOnChange Properties to Dependency Properties

What is the best way of converting the fictional code below to dependency properties? Where the Date Property will be in another control?

    [DependsOn("Date")]
    public int Year
    {
        get { return Date.Year; }
        set { Date.Year = value; }
    }

    [NotifyOnChange]
   开发者_开发百科 public DateTime Date
    {
        get; set; 
    }


Dependency properties can be dependent on one another via Binding, Style, Trigger, Template etc. In certain cases they inherit values like DataContext. In other cases they copy the values of the owner like Border's background color.

In your case do you want to create two dependency properties which by default depend on each other at declaration level itself i.e. in code behind?

If so, your Date can be one Dep.Prop say DateProperty. and Year can be other say YearProperty. In DateProperty and YearProperty's PropertyChangedCallBack metadata, change each other taking care that they do not fall in deadlock.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜