Monday, December 3, 2012

Passing an enum value as command parameter from xaml

Passing an enum value as command parameter from xaml

I want to pass an enum value as command parameter in WPF, something like this -

<Button x:Name="uxSearchButton" Command="{Binding Path=SearchMembersCommand}"          CommandParameter="SearchPageType.First" Content="Search"></Button> 

SearchPageType is an enum and this is to know from which button search command is invoked.

Is this possible in WPF, or how can you pass an enum value as command parameter?

Answers & Comments...

Answer: 1

Try this

<Button CommandParameter="{x:Static local:SearchPageType.First}" .../> 

local - is your namespace reference in the XAML

by : Jobi Joyhttp://stackoverflow.com/users/8091

Answer: 2

You can use property element syntax instead of attribute syntax for this:

<Button x:Name="uxSearchButton"         Command="{Binding Path=SearchMembersCommand}"         Content="Search">     <Button.CommandParameter>         <SearchPageType>First</SearchPageType>     </Button.CommandParameter> </Button> 
by : Robert Macneehttp://stackoverflow.com/users/19273

Answer: 3

Also remember that if your enum is inside another class you need to use the "+" operator.

<Button CommandParameter="{x:Static local:MyOuterType+SearchPageType.First}".../> 
by : tbergelthttp://stackoverflow.com/users/321481




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog