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

1 Comment »

  1. I feel that is among the so much significant info for me.
    And i’m satisfied studying your article. However
    should statement on some common things, The web site taste is perfect,
    the articles is actually nice : D. Excellent task, cheers

    Comment by this page — 2018.11.24 @ 05:42 | Reply


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 )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: