WPF 关于日历控件左右点不动的解决方案

工作笔记

private static ChildItem FindVisualChildItem(DependencyObject obj, string name) where ChildItem : FrameworkElement
        {
            if (null != obj)
            {
                for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
                {
                    DependencyObject child = VisualTreeHelper.GetChild(obj, i);
                    if (child != null && child is ChildItem && (child as ChildItem).Name.Equals(name))
                    {
                        return (ChildItem)child;
                    }
                    else
                    {
                        ChildItem childOfChild = FindVisualChildItem(child, name);
                        if (childOfChild != null && (childOfChild as ChildItem).Name.Equals(name))
                        {
                            return childOfChild;
                        }
                    }
                }
            }
            return null;
        }



        void calendar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("calendar MouseLeftButtonDown");

            e.Handled = true;
        }

   
            // Find the Popup in template
            Popup popup = FindVisualChildItem(sender as DatePicker, "PART_Popup");
            var  calendar = (Calendar)popup.Child;

            calendar.MouseLeftButtonDown += new MouseButtonEventHandler(calendar_MouseLeftButtonDown);

            //Get previouts button
            string previousBtnName = "PART_PreviousButton";
            var previousBtn = FindVisualChildItem

你可能感兴趣的:(WPF 关于日历控件左右点不动的解决方案)