- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我只是想将两个控件绑定(bind)为命令参数,并将它们作为 object[]
传递到我的命令中。
XAML:
<UserControl.Resources>
<C:MultiValueConverter x:Key="MultiParamConverter"></C:MultiValueConverter>
</UserControl.Resources>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<Button Name="Expander" Content="+" Width="25" Margin="4,0,4,0" Command="{Binding ExpanderCommand}">
<Button.CommandParameter>
<MultiBinding Converter="{StaticResource MultiParamConverter}">
<Binding ElementName="Content"/>
<Binding ElementName="Expander"/>
</MultiBinding>
</Button.CommandParameter>
</Button>
<Label FontWeight="Bold">GENERAL INFORMATION</Label>
</StackPanel>
<StackPanel Name="Content" Orientation="Vertical" Visibility="Collapsed">
<Label>Test</Label>
</StackPanel>
</StackPanel>
命令:
public ICommand ExpanderCommand
{
get
{
return new RelayCommand(delegate(object param)
{
var args = (object[])param;
var content = (UIElement)args[0];
var button = (Button)args[1];
content.Visibility = (content.Visibility == Visibility.Visible) ? Visibility.Collapsed : Visibility.Visible;
button.Content = (content.Visibility == Visibility.Visible) ? "-" : "+";
});
}
}
转换器:
public class MultiValueConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return values;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException("No two way conversion, one way binding only.");
}
}
基本上发生的事情是绑定(bind)似乎工作正常并且转换器返回一个包含正确值的 object[]
,但是当命令执行时参数是一个 object []
包含相同数量的元素,但它们是 null
。
有人能告诉我为什么 object[]
参数的值被设置为 null
吗?
谢谢,亚历克斯。
最佳答案
这样就可以了:
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
return values.ToArray();
}
看看这个question求解释。
关于c# - WPF CommandParameter MultiBinding 值为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13713814/
我们有一个使用 VS 2015 编写的 WPF 应用程序。该应用程序在整个应用程序的多个位置都有一个错误图标,用户可以使用它来报告错误。它会启动他们的电子邮件客户端向我们的帮助票务系统发送电子邮件。
我想要一个按钮来显示这样的应用程序设置窗口: ViewModel 有点像: class MyViewModel : BindableBase { public M
如何将我当前所在的窗口作为参数传递给命令? 我喜欢在 XAML 标记中这样做: 最佳答案 在我的情况下,提供的答案都没有奏效。 这对我有用: 关于wpf - 将当前窗口作为 CommandP
关闭。这个问题需要debugging details .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 1年前关闭。 Improve this question
我正在尝试通过 CommandParameter 传递 UserName。
我正在尝试将 ViewModel 中的变量作为参数发送到命令。命令看起来像这样: public class EditPersonCommand : ICommand { private bool
我在我的 WPF 应用程序中使用 MVVM Light。 我创建了一个类 RedirectToUriCommandArgument.cs。 public class RedirectToUriComm
我正在尝试在 WPF 应用程序中将 Command 和 CommandParameter 绑定(bind)与按钮一起使用。我有这个完全相同的代码在 Silverlight 中工作得很好,所以我想知道我
是否可以有不同的 Datacontext对于 WPF Command和一个 CommandParameter ?
我有一个从 ItemsSource 创建的树 View 的 SecondViewModel实例,与我的 Window DataContext 不同。 我想通过`CommandParameter 发送属
如何通过True到 CommandParameter ? 目前我正在强制添加 Boolean.True到资源字典,但这似乎是一种笨拙的方法。 最佳答案 由于命令参数属于“对象”类型,因此 XAML 解
我有一个带有“MainView”和一些嵌套 View 的 Catel 应用程序。 嵌套 View 具有 ListView一些项目有 ContextMenu与一些 MenuItems . 在 MainV
我想得到 NamePlaylist的Item我点击一个MenuContext。但是参数总是空的,我不知道为什么。 这是 ListView 中的菜单 XML
是否可以在多重绑定(bind)中使用 CommandParameter="{Binding}"? 我正在尝试在数据网格中执行此操作。
我正在使用来自 AlexeyZakharov's weblog 的类 InvokeDelegateCommandAction根据一些人的建议,这是将参数从 View 发送回 EventTrigger
我通过 Google 和 StackOverflow 进行了很多搜索,但没有任何答案可以解决我的问题。 我有两个 Xaml 文件: MainWindow.xaml
也许这是一个愚蠢的问题,但我找不到答案:在下面的 xaml 中 CommandParameter 是什么?绑定(bind)到?或者一般来说,"{Binding}" 是什么意思?意思是? 最佳答案 {
我想通过xaml中的commandparameter将多个参数传递给命令。 在上面的示例中,我想将其他变量传递给 ID 变量旁边的命令。我怎样才能实现它?非常感谢。 最佳答案 您可以将MultiBi
我有以下 XAML: 当 GridPrintCommand 执行时,其传
我想在我的类 CommandProvider 中实现 CommandParameter,它用于命令(按钮等)并继承自 ICommand,但我不明白如何实现它。示例: XAML
我是一名优秀的程序员,十分优秀!