日期:2014-05-18 浏览次数:21013 次
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则是改变触发