private void Initialize() { var grid = new Grid(); inkCanvas = new InkCanvas(); inkCanvas.SetValue(Grid.HorizontalAlignmentProperty, HorizontalAlignment.Stretch); inkCanvas.SetValue(Grid.VerticalAlignmentProperty, VerticalAlignment.Stretch); grid.Children.Add(inkCanvas); inkPresenter = inkCanvas.InkPresenter; inkPresenter.StrokesCollected += (sender, e) => OnStrokeCompleted(); inkPresenter.InputDeviceTypes = CoreInputDeviceTypes.Touch | CoreInputDeviceTypes.Pen | CoreInputDeviceTypes.Mouse; // get some defaults var settings = new ImageConstructionSettings(); settings.ApplyDefaults(); StrokeWidth = settings.StrokeWidth.Value; StrokeColor = settings.StrokeColor.Value; HorizontalContentAlignment = HorizontalAlignment.Stretch; VerticalContentAlignment = VerticalAlignment.Stretch; Content = grid; IsEnabledChanged += delegate { inkPresenter.IsInputEnabled = IsEnabled; }; }
protected override void OnStartup(StartupEventArgs e) { myWindow = new Window(); // Create new Canvas // and connect it to the top-level Window myCanvas = new Canvas(); myWindow.Content = myCanvas; myIC = new InkCanvas(); // You must set a background to get stroke events myIC.Background = Brushes.LightGray; // Get each stroke as it is added to the InkCanvas myIC.StrokeCollected += new InkCanvasStrokeCollectedEventHandler(myIC_StrokeCollected); myIC.SetValue(Canvas.TopProperty, 30d); myIC.SetValue(Canvas.LeftProperty, 30d); myIC.SetValue(Canvas.WidthProperty, 450d); myIC.SetValue(Canvas.HeightProperty, 400d); // Add the InkCanvas to the Canvas myCanvas.Children.Add(myIC); myLabel = new Label(); myLabel.Background = Brushes.Salmon; myLabel.SetValue(Canvas.TopProperty, 30d); myLabel.SetValue(Canvas.LeftProperty, 500d); myLabel.SetValue(Canvas.WidthProperty, 450d); myLabel.SetValue(Canvas.HeightProperty, 400d); // Add the Label to the Canvas myCanvas.Children.Add(myLabel); // Associate Visual collection with Label //myVisuals = VisualOperations.GetChildren(myLabel); myMatrix = new Matrix(); // Shrink the new Stroke by 50% in both dimensions // The new Stroke added to the label should appear // in the upper-left quadrant myMatrix.Scale(0.5, 0.5); // Display the Window myWindow.Show(); }
protected override void OnStartup(StartupEventArgs e) { myWindow = new Window(); myCanvas = new Canvas(); myWindow.Content = myCanvas; inkCanvas1 = new InkCanvas(); inkCanvas1.StrokeCollected += new InkCanvasStrokeCollectedEventHandler(myIC_StrokeCollected); inkCanvas1.Background = Brushes.LightGray; inkCanvas1.SetValue(Canvas.TopProperty, 30d); inkCanvas1.SetValue(Canvas.LeftProperty, 30d); inkCanvas1.SetValue(Canvas.WidthProperty, 450d); inkCanvas1.SetValue(Canvas.HeightProperty, 400d); myCanvas.Children.Add(inkCanvas1); Rectangle box = new Rectangle(); box.Height = 100; box.Width = 100; box.Stroke = Brushes.Black; InkCanvas.SetLeft(box, 100); InkCanvas.SetTop(box, 100); inkCanvas1.Children.Add(box); //add the stack panel and radio buttons; buttonPanel = new StackPanel(); buttonPanel.Width = 200; buttonPanel.Height = 400; Canvas.SetLeft(buttonPanel, 500); Canvas.SetTop(buttonPanel, 30); myCanvas.Children.Add(buttonPanel); rbclipWithPoints = new RadioButton(); rbclipWithPoints.Content = "ClipWithPoints"; rbclipWithPoints.Click += new RoutedEventHandler(rbclipWithPoints_Click); buttonPanel.Children.Add(rbclipWithPoints); rbClipWithRect = new RadioButton(); rbClipWithRect.Content = "ClipWithRect"; rbClipWithRect.Click += new RoutedEventHandler(rbClipWithRect_Click); buttonPanel.Children.Add(rbClipWithRect); rbChangeColorWithStylusShape = new RadioButton(); rbChangeColorWithStylusShape.Content = "ChangeColorWithStylusShape"; rbChangeColorWithStylusShape.Click += new RoutedEventHandler(rbChangeColorWithStylusShape_Click); buttonPanel.Children.Add(rbChangeColorWithStylusShape); rbChangeColorWithRect = new RadioButton(); rbChangeColorWithRect.Content = "ChangeColorWithRect"; rbChangeColorWithRect.Click += new RoutedEventHandler(rbChangeColorWithRect_Click); buttonPanel.Children.Add(rbChangeColorWithRect); rbChangeColorWithPoints = new RadioButton(); rbChangeColorWithPoints.Content = "ChangeColorWithPoints"; rbChangeColorWithPoints.Click += new RoutedEventHandler(rbChangeColorWithPoints_Click); buttonPanel.Children.Add(rbChangeColorWithPoints); rbChangeColorAtPoint = new RadioButton(); rbChangeColorAtPoint.Content = "ChangeColorAtPoint"; rbChangeColorAtPoint.Click += new RoutedEventHandler(rbChangeColorAtPoint_Click); buttonPanel.Children.Add(rbChangeColorAtPoint); rbEraseWithStylusShape = new RadioButton(); rbEraseWithStylusShape.Content = "EraseWithStylusShape"; rbEraseWithStylusShape.Click += new RoutedEventHandler(rbEraseWithStylusShape_Click); buttonPanel.Children.Add(rbEraseWithStylusShape); rbEraseWithPoints = new RadioButton(); rbEraseWithPoints.Content = "EraseWithPoints"; rbEraseWithPoints.Click += new RoutedEventHandler(rbEraseWithPoints_Click); buttonPanel.Children.Add(rbEraseWithPoints); rbEraseWithRect = new RadioButton(); rbEraseWithRect.Content = "EraseWithRect"; rbEraseWithRect.Click += new RoutedEventHandler(rbEraseWithRect_Click); buttonPanel.Children.Add(rbEraseWithRect); myWindow.Show(); }