■ ObjectDataProvider 엘리먼트를 사용해 Colors 클래스의 색상 정적 속성을 구하는 방법을 보여준다.
▶ 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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:local="clr-namespace:TestProject" Width="800" Height="600" Title="ObjectDataProvider 엘리먼트 : Colors 클래스의 색상 정적 속성 구하기" FontFamily="나눔고딕코딩" FontSize="16"> <Window.Resources> <ObjectDataProvider x:Key="ColorsTypeObjectDataProviderKey" ObjectType="{x:Type sys:Type}" MethodName="GetType"> <ObjectDataProvider.MethodParameters> <sys:String> System.Windows.Media.Colors, PresentationCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 </sys:String> </ObjectDataProvider.MethodParameters> </ObjectDataProvider> <ObjectDataProvider x:Key="ColorsPropertyObjectDataProviderKey" ObjectInstance="{StaticResource ColorsTypeObjectDataProviderKey}" MethodName="GetProperties" /> </Window.Resources> <Grid> <Grid Margin="10"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="10" /> <ColumnDefinition Width="200" /> </Grid.ColumnDefinitions> <Border Grid.Column="0" BorderThickness="1" BorderBrush="Black"> <Rectangle Name="rectangle"> <Rectangle.Fill> <local:CustomBrush x:Name="customBrush" /> </Rectangle.Fill> </Rectangle> </Border> <Grid Grid.Column="2"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <Label Grid.Row="0" Content="그라디언트" /> <ListBox Name="colorListBox" Grid.Row="1" Margin="0 10 0 0"> <ListBox.ItemTemplate> <DataTemplate> <Rectangle HorizontalAlignment="Center" Width="170" Height="20" Fill="{Binding Path=Name}" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox> <StackPanel Grid.Row="2" Margin="0 10 0 0" Orientation="Horizontal"> <ComboBox Name="colorComboBox" Width="90" Height="25" ItemsSource="{Binding Source={StaticResource ColorsPropertyObjectDataProviderKey}}"> <ComboBox.ItemTemplate> <DataTemplate> <Rectangle Width="70" Height="20" Fill="{Binding Path=Name}" /> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> <Button Name="addButton" Margin="10 0 0 0" Width="50" Content="추가" /> <Button Name="deleteButton" Margin="10 0 0 0" Width="40" Content="삭제" /> </StackPanel> <Label Grid.Row="3" Margin="0 10 0 0" Content="그라디언트 크기" /> <Slider Grid.Row="4" Margin="0 10 0 0" Minimum="10" Maximum="600" Value="{Binding GradientSize, ElementName=customBrush}" /> <Label Grid.Row="5" Margin="0 10 0 0" Content="그라디언트 디테일" /> <Slider Grid.Row="6" Margin="0 10 0 0" Minimum="0.1" Maximum="100" Value="{Binding GradientDetail, ElementName=customBrush}" /> </Grid> </Grid> </Grid> </Window> |