本文整理汇总了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;
}