Pasar un valor de enumeración como parámetro de comando desde XAML
Quiero pasar un valor de enumeración como parámetro de comando en WPF, usando algo como esto:
<Button
x:Name="uxSearchButton"
Command="{Binding Path=SearchMembersCommand}"
CommandParameter="SearchPageType.First"
Content="Search">
</Button>
SearchPageType
es una enumeración y esto es para saber desde qué botón se invoca el comando de búsqueda.
¿Es esto posible en WPF, o cómo puede pasar un valor de enumeración como parámetro de comando?
165
4 answers
Prueba esto
<Button CommandParameter="{x:Static local:SearchPageType.First}" .../>
local
- es su referencia de espacio de nombres en el XAML
244
Author: Jobi Joy,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-12-03 05:30:18
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-12-03 05:30:18
También recuerde que si su enumeración está dentro de otra clase, debe usar el operador +
.
<Button CommandParameter="{x:Static local:MyOuterType+SearchPageType.First}".../>
151
Author: tbergelt,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-12-04 07:03:40
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-12-04 07:03:40
Puede usar la sintaxis del elemento de propiedad en lugar de la sintaxis del atributo para esto:
<Button x:Name="uxSearchButton"
Command="{Binding Path=SearchMembersCommand}"
Content="Search">
<Button.CommandParameter>
<SearchPageType>First</SearchPageType>
</Button.CommandParameter>
</Button>
42
Author: Robert Macnee,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2008-12-11 19:48:32
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2008-12-11 19:48:32
También si desea proporcionar una enumeración [Flags
] puede usar la sintaxis del elemento de propiedad:
<Button>
<Button.CommandParameter>
<SearchPageType>First,Second</SearchPageType>
<Button.CommandParameter>
</Button>
27
Author: hartmape,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-02-11 04:59:35
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-02-11 04:59:35