日期:2014-05-18  浏览次数:21013 次

WPF自定义日历控件
http://download.csdn.net/detail/samsone/4243102
Changed事件该怎么样改下?
我第1次选择时间正常、 第2次选择同样的时间就不会响应...

------解决方案--------------------
C# code

public NcCalendarControl() {
    this.SetValue(ItemsProperty, new NcCalendar(DateTime.Now));
    Items.SelectedChanged += new EventHandler(Items_SelectedChanged);

    this.Loaded += OnLoaded;
}

void OnLoaded(object sender, RoutedEventArgs e) {
    FindChild<ToggleButton>(this, p => {
        Console.WriteLine(p.GetType().Name);
        p.Click += (s1, e1) => {
            Items_SelectedChanged(p, EventArgs.Empty);
        };
    });
}

private T FindChild<T>(DependencyObject parent, Action<T> invocation) where T : DependencyObject {
    if (parent == null) return null;
    T childElement = null;
    int childrenCount = VisualTreeHelper.GetChildrenCount(parent);
    for (int i = 0; i < childrenCount; i++) {
        var child = VisualTreeHelper.GetChild(parent, i);
        if (child is T) {
            invocation(child as T);
        }
        FindChild<T>(child, invocation);
    }

    return childElement;
}

------解决方案--------------------
那就在每个Toggle加上Click
然后先Click,然后Select
Click每次触发,而Select则是改变触发