列挙体の値をバインドするには <ObjectDataProvidor> 要素を使用します。
(参考文献:MSDN)
この ObjectDataProvidor を使用するには、名前空間 xmlns:sys=”clr-namespace:System;assembly=mscorlib” が必要です。
DayOfWeek 列挙体の全ての値をを取り出してListBoxにバインドする例を下記に示します。
XAMLの例
<Window x:Class="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" Title="MainWindow" Height="194" Width="175"> <Window.Resources> <ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="DayOfWeekValues"> <ObjectDataProvider.MethodParameters> <x:Type TypeName="sys:DayOfWeek" /> </ObjectDataProvider.MethodParameters> </ObjectDataProvider> </Window.Resources> <Grid> <ListBox Name="myComboBox" SelectedIndex="0" Margin="8" ItemsSource="{Binding Source={StaticResource DayOfWeekValues}}"/> </Grid> </Window>