当前位置: 首页>>代码示例>>C#>>正文


C# Canvas.AddHandler方法代码示例

本文整理汇总了C#中System.Windows.Controls.Canvas.AddHandler方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.AddHandler方法的具体用法?C# Canvas.AddHandler怎么用?C# Canvas.AddHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.Canvas的用法示例。


在下文中一共展示了Canvas.AddHandler方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MapViewModel

        public MapViewModel()
        {
            CreateCommands();
            LayerViewModel = ServiceLocator.Current.GetInstance<LayerViewModel>();

            _mapCanvas = new Canvas();
            MousePosition = new Point();
            _tempTiles = new List<Tile>();
            _selectionRect = new Rectangle();
            _selectionPointEnd = new Point();
            _selectionPointStart = new Point();
            _tempSelectedTileList = new List<Tile>();

            _editor = _modelInstance._editor;
            _mapCanvas.HorizontalAlignment = HorizontalAlignment.Left;
            _mapCanvas.VerticalAlignment = VerticalAlignment.Top;

            _mapCanvas.Background = Brushes.Transparent;
            _mapCanvas.Width = _editor.GetMapWidth() * _editor.GetTileSize();
            _mapCanvas.Height = _editor.GetMapHeight() * _editor.GetTileSize();

            _mapCanvas.AddHandler(UIElement.MouseRightButtonDownEvent, (RoutedEventHandler)SelectBegin);
            _mapCanvas.AddHandler(UIElement.MouseRightButtonUpEvent, (RoutedEventHandler)SelectEnd);

            _mapCanvas.AddHandler(UIElement.MouseMoveEvent, (RoutedEventHandler)Click);
            _mapCanvas.AddHandler(UIElement.MouseDownEvent, (RoutedEventHandler)Click);
            _mapCanvas.AddHandler(UIElement.MouseLeftButtonUpEvent, (RoutedEventHandler)ClickEnd);

            int mapWidth = _editor.GetMapWidth();
            int mapHeight = _editor.GetMapHeight();

            for (int y = 0; y < mapHeight; y++)
            {
                for (int x = 0; x < mapWidth; x++)
                {
                    Tile t = _editor.GetTile(x, y);
                    _mapCanvas.Children.Add(t);
                    Canvas.SetTop(t, y * 32);
                    Canvas.SetLeft(t, x * 32);
                }
            }

            _selectionRect.Fill = new SolidColorBrush(Colors.Black);
            _selectionRect.Stroke = new SolidColorBrush(Colors.Black);
            _selectionRect.Width = 32;
            _selectionRect.Height = 32;
            _selectionRect.Opacity = 0.5;
        }
开发者ID:eivhyl,项目名称:PG5200_Innlevering2,代码行数:48,代码来源:MapViewModel.cs


注:本文中的System.Windows.Controls.Canvas.AddHandler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。