■ InkCanvas 클래스의 GetSelectedStrokes 메소드를 사용해 선택 스트로크 색상을 변경하는 방법을 보여준다.
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ink="clr-namespace:System.Windows.Ink;assembly=PresentationCore" Width="800" Height="600" Title="TestProject" FontFamily="나눔고딕코딩" FontSize="16"> <Grid> <InkCanvas Name="inkCanvas" Background="Ivory"> <InkCanvas.DefaultDrawingAttributes> <ink:DrawingAttributes Color="Red" Width="5" /> </InkCanvas.DefaultDrawingAttributes> </InkCanvas> <StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10" Orientation="Vertical"> <Button Name="inkButton" HorizontalAlignment="Left" Width="100" Height="30" Content="잉크" /> <Button Name="highlightButton" HorizontalAlignment="Left" Margin="0 10 0 0" Width="120" Height="30" Content="하이라이트" /> <Button Name="eraseStrokeButton" HorizontalAlignment="Left" Margin="0 10 0 0" Width="150" Height="30" Content="스트로크 지우기" /> <Button Name="selectButton" HorizontalAlignment="Left" Margin="0 10 0 0" Width="100" Height="30" Content="선택하기" /> <Button Name="changeColorButton" HorizontalAlignment="Left" Margin="0 10 0 0" Width="200" Height="30" Content="선택 스트로크 색상 변경" /> </StackPanel> </Grid> </Window> |
▶ MainWindow.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
using System.Windows; using System.Windows.Controls; using System.Windows.Ink; using System.Windows.Media; namespace TestProject { /// <summary> /// 메인 윈도우 /// </summary> public partial class MainWindow : Window { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainWindow() /// <summary> /// 생성자 /// </summary> public MainWindow() { InitializeComponent(); this.inkButton.Click += inkButton_Click; this.highlightButton.Click += highlightButton_Click; this.selectButton.Click += selectButton_Click; this.eraseStrokeButton.Click += eraseStrokeButton_Click; this.changeColorButton.Click += changeColorButton_Click; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 잉크 버튼 클릭시 처리하기 - inkButton_Click(sender, e) /// <summary> /// 잉크 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void inkButton_Click(object sender, RoutedEventArgs e) { this.inkCanvas.EditingMode = InkCanvasEditingMode.Ink; this.inkCanvas.DefaultDrawingAttributes.Height = 2; this.inkCanvas.DefaultDrawingAttributes.Color = Colors.Red; this.inkCanvas.DefaultDrawingAttributes.IsHighlighter = false; } #endregion #region 하이라이트 버튼 클릭시 처리하기 - highlightButton_Click(sender, e) /// <summary> /// 하이라이트 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void highlightButton_Click(object sender, RoutedEventArgs e) { this.inkCanvas.EditingMode = InkCanvasEditingMode.Ink; this.inkCanvas.DefaultDrawingAttributes.Height = 25; this.inkCanvas.DefaultDrawingAttributes.Color = Colors.Yellow; this.inkCanvas.DefaultDrawingAttributes.IsHighlighter = true; } #endregion #region 스트로크 지우기 버튼 클릭시 처리하기 - eraseStrokeButton_Click(sender, e) /// <summary> /// 스트로크 지우기 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void eraseStrokeButton_Click(object sender, RoutedEventArgs e) { this.inkCanvas.EditingMode = InkCanvasEditingMode.EraseByStroke; } #endregion #region 선택하기 버튼 클릭시 처리하기 - selectButton_Click(sender, e) /// <summary> /// 선택하기 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void selectButton_Click(object sender, RoutedEventArgs e) { this.inkCanvas.EditingMode = InkCanvasEditingMode.Select; } #endregion #region 선택 스트로크 색상 변경 버튼 클릭시 처리하기 - changeColorButton_Click(sender, e) /// <summary> /// 선택 스트로크 색상 변경 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void changeColorButton_Click(object sender, RoutedEventArgs e) { StrokeCollection strokeCollection = this.inkCanvas.GetSelectedStrokes(); if(strokeCollection.Count > 0) { foreach(Stroke stroke in strokeCollection) { stroke.DrawingAttributes.Color = Colors.Blue; } } } #endregion } } |