private void DrawMethod(IDrawController Controller, double X, double Y) { Shape _shape = Controller.Draw(double.Parse(txB_NumbA.Text), double.Parse(txB_NumbB.Text)); cnv_Main.Children.Add(_shape); Canvas.SetTop(_shape, Y - _shape.Height / 2); Canvas.SetLeft(_shape, X - _shape.Width / 2); _shape.MouseDown += Shape_MouseDown; }
private void cnv_Main_MouseDown(object sender, MouseButtonEventArgs e) { //определение контроллера в зависимости от выбранной фигуры для рисования //функция DrawMethod вынесена отдельно чтобы избежать дублирования кода if (e.LeftButton == MouseButtonState.Pressed && chB_Drawing.IsChecked == true) { if (chB_drawCircle.IsChecked == true) { Controller = Container.Resolve <CircleController>(); DrawMethod(Controller, e.GetPosition(cnv_Main).X, e.GetPosition(cnv_Main).Y); } else if (chB_drawRect.IsChecked == true) { Controller = Container.Resolve <RectController>(); DrawMethod(Controller, e.GetPosition(cnv_Main).X, e.GetPosition(cnv_Main).Y); } else if (chB_drawEllipse.IsChecked == true) { Controller = Container.Resolve <EllipseController>(); DrawMethod(Controller, e.GetPosition(cnv_Main).X, e.GetPosition(cnv_Main).Y); } } }