Ejemplo n.º 1
0
 void ModesBox_OnSelectionChanged(object Sender, SelectionChangedEventArgs E)
 {
     if (ModesBox.SelectedValue is ExtendedInkTool tool)
     {
         InkCanvas.SetInkTool(tool);
     }
 }
Ejemplo n.º 2
0
        public ImageEditorWindow()
        {
            InitializeComponent();

            if (DataContext is ImageEditorViewModel vm)
            {
                vm.ObserveProperty(M => M.TransformedBitmap)
                .Subscribe(M => UpdateInkCanvas());

                vm.InkCanvas = InkCanvas;
                vm.Window    = this;

                InkCanvas.Strokes.StrokesChanged += (S, E) =>
                {
                    var item = new StrokeHistory();

                    item.Added.AddRange(E.Added);
                    item.Removed.AddRange(E.Removed);

                    vm.AddInkHistory(item);
                };

                void SelectionMovingOrResizing(object Sender, InkCanvasSelectionEditingEventArgs Args)
                {
                    vm.AddSelectHistory(new SelectHistory
                    {
                        NewRect   = Args.NewRectangle,
                        OldRect   = Args.OldRectangle,
                        Selection = InkCanvas.GetSelectedStrokes()
                    });
                }

                InkCanvas.SelectionMoving   += SelectionMovingOrResizing;
                InkCanvas.SelectionResizing += SelectionMovingOrResizing;

                var inkCanvasVm = vm.InkCanvasViewModel;

                inkCanvasVm
                .SelectedColor
                .Subscribe(M => InkCanvas.DefaultDrawingAttributes.Color = M);

                inkCanvasVm
                .BrushSize
                .Subscribe(M => InkCanvas.DefaultDrawingAttributes.Height = InkCanvas.DefaultDrawingAttributes.Width = M);

                inkCanvasVm
                .SelectedTool
                .Subscribe(M => InkCanvas.SetInkTool(M));
            }

            Image.SizeChanged += (S, E) => UpdateInkCanvas();

            InkCanvas.DefaultDrawingAttributes.FitToCurve = true;
        }