c# – 如何绑定WPF工具包中的日程表日历控件?

c# – 如何绑定WPF工具包中的日程表日历控件?,第1张

概述我想绑定一个日期列表到BlackoutDates属性,但它似乎是不可能的.特别是在MVVM场景中.有没有人完成这样的事情?有没有任何良好的日历控件,使MVVM播放很好? 对于您的DatePicker困境,我发现使用附加属性(从我使用CommandBindings修改)的整洁的黑客: class AttachedProperties : DependencyObject{ #region 我想绑定一个日期列表到BlackoutDates属性,但它似乎是不可能的.特别是在MVVM场景中.有没有人完成这样的事情?有没有任何良好的日历控件,使MVVM播放很好?解决方法 对于您的DatePicker困境,我发现使用附加属性(从我使用CommandBindings修改)的整洁的黑客:
class AttachedPropertIEs : DependencyObject{    #region RegisterBlackoutDates    // Adds a collection of command bindings to a date picker's existing BlackoutDates collection,since the collections are immutable and can't be bound to otherwise.    //    // Usage: <DatePicker Hacks:AttachedPropertIEs.RegisterBlackoutDates="{Binding BlackoutDates}" >    public static DependencyProperty RegisterBlackoutDatesProperty = DependencyProperty.Registerattached("RegisterBlackoutDates",typeof(System.windows.Controls.CalendarBlackoutDatesCollection),typeof(AttachedPropertIEs),new PropertyMetadata(null,OnRegisterCommandBindingChanged));    public static voID SetRegisterBlackoutDates(UIElement element,System.windows.Controls.CalendarBlackoutDatesCollection value)    {        if (element != null)            element.SetValue(RegisterBlackoutDatesProperty,value);    }    public static System.windows.Controls.CalendarBlackoutDatesCollection GetRegisterBlackoutDates(UIElement element)    {        return (element != null ? (System.windows.Controls.CalendarBlackoutDatesCollection)element.GetValue(RegisterBlackoutDatesProperty) : null);    }    private static voID OnRegisterCommandBindingChanged(DependencyObject sender,DependencyPropertyChangedEventArgs e)    {        System.windows.Controls.DatePicker element = sender as System.windows.Controls.DatePicker;        if (element != null)        {            System.windows.Controls.CalendarBlackoutDatesCollection bindings = e.NewValue as System.windows.Controls.CalendarBlackoutDatesCollection;            if (bindings != null)            {                element.BlackoutDates.Clear();                foreach (var daterange in bindings)                {                    element.BlackoutDates.Add(daterange);                }            }        }    }    #endregion}

我相信我太晚了,不能帮助你,但希望别人会觉得有用.

总结

以上是内存溢出为你收集整理的c# – 如何绑定WPF工具包中的日程表日历控件?全部内容,希望文章能够帮你解决c# – 如何绑定WPF工具包中的日程表日历控件?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1236236.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存