Ejemplo n.º 1
0
 //private void SelectedLayerChangedCommandDo(int? layerIndex)
 //{
 //    if (layerIndex == null || layerIndex == SelectedLayer)
 //        return;
 //    _selectedLayer = (int)layerIndex;
 //    //GridMapItems.Clear();
 //    for (int i = 0; i < _map.RackCount; i++)
 //    {
 //        for(int j = 0; j < _map.ColumnCount; j++)
 //        {
 //            GridMapItems[i * _map.ColumnCount + j].SingleStorage = _map[_selectedLayer, i, j];
 //            string color = "#";
 //            Random random = new Random();
 //            for(int c = 0; c < 3; c++)
 //            {
 //                if (random.NextDouble() > 0.5)
 //                    color += "ff";
 //                else
 //                    color += "00";
 //            }
 //            GridMapItems[i * _map.ColumnCount + j].Color = color;
 //        }
 //    }
 //}
 private void ExcuteAreaCanvasLeftButtonDownCommandDo(Models.ExParameters p)
 {
     //Canvas canvas = p.Parameter as Canvas;
     //MouseButtonEventArgs e = p.EventArgs as MouseButtonEventArgs;
     //Point point = e.GetPosition(canvas);
     //DownPoint = point;
 }
Ejemplo n.º 2
0
        private void ExcuteAreaCanvasLeftButtonUpCommandDo(Models.ExParameters p)
        {
            if (!CanGridMapSelect)
            {
                return;
            }
            Canvas canvas          = p.Parameter as Canvas;
            MouseButtonEventArgs e = p.EventArgs as MouseButtonEventArgs;
            Point point            = e.GetPosition(canvas);

            if (!(DownPoint.X == 0 && DownPoint.Y == 0) &&
                Math.Abs(DownPoint.X - point.X) > AreaThreshold && Math.Abs(DownPoint.Y - point.Y) > AreaThreshold)
            {
                //To set Selected ListBox Item
                for (int i = 0; i < gridMapItems.Count; i++)
                {
                    if ((gridMapItems[i].TopPad + gridMapItems[i].Height > AreaRectTopPad && gridMapItems[i].TopPad < AreaRectTopPad + AreaRectHeight) &&
                        (gridMapItems[i].LeftPad + gridMapItems[i].Width > AreaRectLeftPad && gridMapItems[i].LeftPad < AreaRectLeftPad + AreaRectWidth))
                    {
                        gridMapItems[i].IsSelected = true;
                    }
                    else
                    {
                        gridMapItems[i].IsSelected = false;
                    }
                }
            }
            ExecuteModifyCommand.RaiseCanExecuteChanged();
            AreaRectHeight  = 0;
            AreaRectLeftPad = 0;
            AreaRectWidth   = 0;
            AreaRectHeight  = 0;
            DownPoint       = new Point();
        }
        /// <summary>
        /// 调用操作。
        /// </summary>
        /// <param name="parameter">操作的参数。如果操作不需要参数,则可以将参数设置为空引用。</param>
        protected override void Invoke(object parameter)
        {
            if (base.AssociatedObject != null)
            {
                ICommand command = this.ResolveCommand();

                /*
                 * ★★★★★★★★★★★★★★★★★★★★★★★★
                 * 注意这里添加了事件触发源和事件参数
                 * ★★★★★★★★★★★★★★★★★★★★★★★★
                 */
                Models.ExParameters exParameter = new Models.ExParameters
                {
                    Sender    = base.AssociatedObject,
                    Parameter = GetValue(CommandParameterProperty),
                    EventArgs = parameter as EventArgs
                };

                if (command != null && command.CanExecute(exParameter))
                {
                    /*
                     * ★★★★★★★★★★★★★★★★★★★★★★★★
                     * 注意将扩展的参数传递到Execute方法中
                     * ★★★★★★★★★★★★★★★★★★★★★★★★
                     */
                    command.Execute(exParameter);
                }
            }
        }
Ejemplo n.º 4
0
        private void ExcuteAreaCanvasMoveCommandDo(Models.ExParameters p)
        {
            if (!CanGridMapSelect)
            {
                return;
            }
            Canvas         canvas = p.Parameter as Canvas;
            MouseEventArgs e      = p.EventArgs as MouseEventArgs;
            Point          point  = e.GetPosition(canvas);

            //System.Diagnostics.Debug.WriteLine(point.X + "--" + point.Y + "=================" + DownPoint.X + "--" + DownPoint.Y);
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                if (DownPoint.X == 0 && DownPoint.Y == 0)
                {
                    DownPoint = point;
                }
                AreaRectWidth   = Math.Abs(point.X - DownPoint.X);
                AreaRectHeight  = Math.Abs(point.Y - DownPoint.Y);
                AreaRectLeftPad = Math.Min(point.X, DownPoint.X);
                AreaRectTopPad  = Math.Min(point.Y, DownPoint.Y);
            }
        }