Files
docs-desktop/dotnet-desktop-guide/net/wpf/data/snippets/how-to-bind-to-an-enumeration/csharp/BindEnumFull.xaml
T
Andy (Steve) De GeorgeandTom Dykstra 3885aab154 Add how to bind enum article (#1056)
* add how to article

* Fix lint

* Fix the code example

* Add missing code

* Update how-to-bind-to-an-enumeration.md

* Update dotnet-desktop-guide/net/wpf/data/how-to-bind-to-an-enumeration.md

Co-authored-by: Tom Dykstra <[email protected]>

Co-authored-by: Tom Dykstra <[email protected]>
2021-05-06 08:03:42 -07:00

27 lines
1.1 KiB
XML

<Window x:Class="ArticleExample.BindEnumFull"
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"
SizeToContent="WidthAndHeight"
Title="Enum binding">
<Window.Resources>
<ObjectDataProvider x:Key="EnumDataSource"
ObjectType="{x:Type sys:Enum}"
MethodName="GetValues">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="HorizontalAlignment" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources>
<StackPanel Width="300" Margin="10">
<TextBlock>Choose the HorizontalAlignment value of the Button:</TextBlock>
<ListBox Name="myComboBox" SelectedIndex="0"
ItemsSource="{Binding Source={StaticResource EnumDataSource}}"/>
<Button Content="I'm a button"
HorizontalAlignment="{Binding ElementName=myComboBox, Path=SelectedItem}" />
</StackPanel>
</Window>