■ ObjectDataProvider 엘리먼트를 사용해 열거형 타입을 구하는 방법을 보여준다.
▶ OrderStatus.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 |
namespace TestProject { /// <summary> /// 주문 상태 /// </summary> public enum OrderStatus { /// <summary> /// 해당 무 /// </summary> None, /// <summary> /// 신규 /// </summary> New, /// <summary> /// 처리중 /// </summary> Processing, /// <summary> /// 배송 /// </summary> Shipped, /// <summary> /// 수신 /// </summary> Received }; } |
▶ 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 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:local="clr-namespace:TestProject" Width="800" Height="600" Title="ObjectDataProvider 엘리먼트 : 열거형 타입 구하기" FontFamily="나눔고딕코딩" FontSize="16"> <Window.Resources> <ObjectDataProvider x:Key="EnumerationObjectDataProviderKey" ObjectType="{x:Type s:Enum}" MethodName="GetValues"> <ObjectDataProvider.MethodParameters> <x:Type Type="local:OrderStatus" /> </ObjectDataProvider.MethodParameters> </ObjectDataProvider> </Window.Resources> <Grid> <ComboBox Name="comboBox" Width="200" Height="25" ItemsSource="{Binding Source={StaticResource EnumerationObjectDataProviderKey}}" SelectedIndex="1" /> </Grid> </Window> |