■ InkCanvas 엘리먼트의 DefaultDrawingAttributes/EditingMode/Strokes 속성을 사용해 바인딩하는 방법을 보여준다.
▶ 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 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 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="800" Height="600" Title="TestProject" FontFamily="나눔고딕코딩" FontSize="16"> <Grid Margin="10"> <Grid.Resources> <x:Array x:Key="InkCanvasEditingModeArrayKey" Type="{x:Type InkCanvasEditingMode}"> <x:Static Member="InkCanvasEditingMode.Ink" /> <x:Static Member="InkCanvasEditingMode.Select" /> <x:Static Member="InkCanvasEditingMode.EraseByPoint" /> <x:Static Member="InkCanvasEditingMode.EraseByStroke" /> </x:Array> <x:Array x:Key="DrawingAttributesArrayKey" Type="{x:Type DrawingAttributes}"> <DrawingAttributes Width="3" Height="3" Color="Black" FitToCurve="true" /> <DrawingAttributes Width="5" Height="5" Color="Blue" FitToCurve="false" /> <DrawingAttributes Width="7" Height="7" Color="Red" FitToCurve="true" /> </x:Array> <DataTemplate DataType="{x:Type DrawingAttributes}"> <Border Width="80" Height="20"> <Border.Background > <SolidColorBrush Color="{Binding Path=Color}" /> </Border.Background> </Border> </DataTemplate> </Grid.Resources> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="10" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="10" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <Border Grid.Column="0" BorderThickness="2" BorderBrush="Black"> <InkCanvas Name="inkCanvas1" Background="LightGray" DefaultDrawingAttributes="{Binding ElementName=drawingAttributesListBox, Path=SelectedItem}" EditingMode="{Binding ElementName=editingModeListBox, Path=SelectedItem}" /> </Border> <Border Grid.Column="2" BorderThickness="2" BorderBrush="Black"> <InkCanvas Background="LightBlue" DefaultDrawingAttributes="{Binding ElementName=inkCanvas1, Path=DefaultDrawingAttributes}" EditingMode="{Binding ElementName=inkCanvas1, Path=EditingMode}" Strokes="{Binding ElementName=inkCanvas1, Path=Strokes}"> <InkCanvas.LayoutTransform> <ScaleTransform ScaleX="-1" ScaleY="1" /> </InkCanvas.LayoutTransform> </InkCanvas> </Border> <StackPanel Grid.Column="4" VerticalAlignment="Center"> <ListBox Name="editingModeListBox" Height="100" Width="100" ItemsSource="{StaticResource InkCanvasEditingModeArrayKey}" /> <ListBox Name="drawingAttributesListBox" Margin="0 10 0 0" Height="100" Width="100" ItemsSource="{StaticResource DrawingAttributesArrayKey}" /> </StackPanel> </Grid> </Window> |