dev gridcontrol把event事件转换成命令

    可以通过继承gridcontrol的形式来实现 定义DataGridDoubleClickCommand依赖属性

class MyGridControl : GridControl
    {

        public ICommand DataGridDoubleClickCommand
        {
            get { return (ICommand)GetValue(DataGridDoubleClickProperty); }
            set { SetValue(DataGridDoubleClickProperty, value); }
        }
        public static readonly DependencyProperty DataGridDoubleClickProperty =
    DependencyProperty.RegisterAttached("DataGridDoubleClickCommand", typeof(ICommand), typeof(MyGridControl),
                      new UIPropertyMetadata());

        public MyGridControl()
        {
            Loaded += MyGridControl_Loaded;
            this.MouseDoubleClick += MyGridControl_MouseDoubleClick;
        }

        void MyGridControl_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (DataGridDoubleClickCommand != null)
            {
                DataGridDoubleClickCommand.Execute(null);
            }
        }

        private void MyGridControl_Loaded(object sender, System.Windows.RoutedEventArgs e) //这段代码为了自适应屏幕
        {
            var tableView = View as TableView;
            tableView.BestFitColumns();
            double actualGridWidth = tableView.IndicatorHeaderWidth + System.Windows.Forms.SystemInformation.VerticalScrollBarWidth;
            IList<DevExpress.Xpf.Grid.GridColumn> gcList = tableView.VisibleColumns;
            foreach (DevExpress.Xpf.Grid.GridColumn gc in gcList)
            {
                actualGridWidth += gc.ActualAdditionalRowDataWidth;
            }
            double blankArea = tableView.ActualWidth - actualGridWidth;
            if (blankArea > 0)
            {
                foreach (DevExpress.Xpf.Grid.GridColumn gc in gcList)
                {
                    gc.Width = gc.ActualWidth + blankArea / gcList.Count;
                }
            }

            tableView.ShowGroupPanel = false;
            tableView.AllowEditing = false;
        }
    }

posted @ 2016-12-15 14:14  beautifulday  阅读(262)  评论(0编辑  收藏  举报