I'm on your side, when times get rough.

2018.04.26

[C#, WPF] Display Enumerations in XAML

Filed under: Programming — Peter_KIM @ 14:12
<Page x:Class="Example"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:System="clr-namespace:System;assembly=mscorlib">
  <Page.Resources>
    <ObjectDataProvider x:Key="DockEnum" MethodName="GetValues" ObjectType="{x:Type System:Enum}" >
      <ObjectDataProvider.MethodParameters>
        <x:Type TypeName="Dock"/>
      </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>
 
    <ObjectDataProvider x:Key="VerticalAlignmentEnum" MethodName="GetValues" ObjectType="{x:Type System:Enum}" >
      <ObjectDataProvider.MethodParameters>
        <x:Type TypeName="VerticalAlignment"/>
      </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>
 
  </Page.Resources>
 
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="*" />
      <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
 
    <ListBox Grid.Row ="0" ItemsSource="{Binding Source={StaticResource DockEnum}}" />
 
    <ComboBox Grid.Row ="1" ItemsSource="{Binding Source={StaticResource VerticalAlignmentEnum}}" />
  </Grid>
 
</Page>

 

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: