일부 작업을 명령으로 변경하려고하므로 MVVM 디자인 패턴을 배우고 있습니다.
예를 들어, MainWindow는 컨테이너로 Canvas를 가지며 사용자는 드래그를 통해 사각형을 그릴 수 있습니다. 그래서 나는 사각형이 취소 호출 후 사라집니다 있도록 실행 취소 기능을 추가 싶어 어쩌면 이후 3 단계 작업을 WPF에서 명령으로 변경하는 방법은 무엇입니까?
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
StartPoint = e.GetPosition(this);
shape = new Rectangle();
shape.Fill = Brushes.Transparent;
shape.Stroke = Brushes.Black;
shape.StrokeThickness = 1;
this.Children.Add(shape);
}
protected override void OnMouseMove(MouseButtonEventArgs e)
{
Point endpoint = e.GetPosition(this);
double left = Math.Min(endpoint.X, StartPoint.X);
double top = Math.Min(endpoint.Y, StartPoint.Y);
shape.Margin = new Thickness(left, top, 0, 0);
shape.Width = Math.Abs(endpoint.X - StartPoint.X);
shape.Height = Math.Abs(endpoint.Y - StartPoint.Y);
shape.Stroke = Brushes.Black;
shape.StrokeThickness = 2;
}
protected override void OnMouseLeave(MouseButtonEventArgs e)
{
//end
}
아래로 코드를 작성, 그래서 나는 한 명령에서 이러한 3 단계를 만들고 싶어. 어떻게해야합니까? 감사.
따라서 UI에 하나의 이벤트 만 연결하면됩니다. Undo 기능에 관해서는 각 사각형을'MouseUp'의'List'에서 생성 할 때마다 저장하려고합니다. 그래서'List'에서 Undo의 마지막 항목을 제거 할 수 있습니다. – Rachel
질문에 대한 답변이 있습니까? – Alan