首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

代码如何贴

2013-07-04 
代码怎么贴public class AttachedPropertyHelper{public static DependencyProperty IsLeafProperty Dep

代码怎么贴


public class AttachedPropertyHelper
    {
        public static DependencyProperty IsLeafProperty = DependencyProperty.RegisterAttached(
            "IsLeaf",
            typeof(bool),
            typeof(AttachedPropertyHelper),
            new FrameworkPropertyMetadata(null)
            );
        public static void SetIsLeaf(DependencyObject obj, bool value)
        {
            obj.SetValue(AttachedPropertyHelper.IsLeafProperty, value);
        }
        public static bool GetIsLeaf(DependencyObject obj)
        {
            return (bool)obj.GetValue(AttachedPropertyHelper.IsLeafProperty);
        }

        public static DependencyProperty MouseDoubleClickProperty = DependencyProperty.RegisterAttached(
            "MouseDoubleClick",
            typeof(ICommand),
            typeof(AttachedPropertyHelper),
            new FrameworkPropertyMetadata(null, new PropertyChangedCallback(MouseDoubleChanged))
            );
        public static void SetMouseDoubleClick(DependencyObject obj, ICommand value)
        {
            obj.SetValue(AttachedPropertyHelper.MouseDoubleClickProperty, value);
        }
        public static ICommand GetMouseDoubleClick(DependencyObject obj)
        {
            return (ICommand)obj.GetValue(AttachedPropertyHelper.MouseDoubleClickProperty);


        }
        public static void MouseDoubleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Control control = d as ContentControl;
            if (control != null)
            {
                if (e.NewValue != null && e.OldValue == null)
                {
                    control.MouseDoubleClick += new MouseButtonEventHandler(control_MouseDoubleClick);
                }
                else if (e.NewValue == null && e.OldValue != null)
                {
                    control.MouseDoubleClick -= new MouseButtonEventHandler(control_MouseDoubleClick);
                }
            }
        }
        public static void control_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            Control control = sender as Control;
            ICommand command = (ICommand)control.GetValue(AttachedPropertyHelper.MouseDoubleClickProperty);
            if (command.CanExecute(control.GetValue(AttachedPropertyHelper.IsLeafProperty)))
            {
                command.Execute(control);
            }
        }


    }


[解决办法]
该回复于2011-07-18 16:01:55被版主删除

热点排行