我有这样的代码(它工作得很好):
<KeyBinding Key="Enter" Command="{Binding ReturnResultCommand}">
<KeyBinding.CommandParameter>
<s:Boolean>
True
</s:Boolean>
</KeyBinding.CommandParameter>
</KeyBinding>其中"s“当然是系统名称空间。
但是这个命令被调用了很多次,它实际上膨胀了非常简单的XAML代码。这真的是XAML中布尔命令参数的最短表示法(除了将命令拆分为几个命令之外)吗?
发布于 2011-02-15 05:48:09
这可能有点麻烦,但您可以从KeyBinding类派生:
public class BoolKeyBinding : KeyBinding
{
public bool Parameter
{
get { return (bool)CommandParameter; }
set { CommandParameter = value; }
}
}用法:
<local:BoolKeyBinding ... Parameter="True"/>和另一个不是很奇怪的解决方案:
xmlns:s="clr-namespace:System;assembly=mscorlib"<Application.Resources>
<!-- ... -->
<s:Boolean x:Key="True">True</s:Boolean>
<s:Boolean x:Key="False">False</s:Boolean>
</Application.Resources>用法:
<KeyBinding ... CommandParameter="{StaticResource True}"/>发布于 2012-11-10 01:47:26
最简单的方法是在参考资料中定义以下内容
<System:Boolean x:Key="FalseValue">False</System:Boolean>
<System:Boolean x:Key="TrueValue">True</System:Boolean>并像这样使用它:
<Button CommandParameter="{StaticResource FalseValue}"/>发布于 2014-08-29 18:53:49
或者,也许是这样:
<Button.CommandParameter>
<s:Boolean>True</s:Boolean>
</Button.CommandParameter>其中s是命名空间:
xmlns:s="clr-namespace:System;assembly=mscorlib"https://stackoverflow.com/questions/4997446
复制相似问题