【发布时间】:2015-11-05 06:50:36
【问题描述】:
我编写了一个自定义的ICommand 实现,它可以作为静态属性使用:
public class GridViewCommands
{
public GridViewCommands()
{
}
/// <summary>
/// Toggle Selection-Command
/// </summary>
public static ICommand ToggleSelection
{
get
{
return new GridViewToggleSelectionCommand();
}
}
}
我尝试将此属性绑定到一个简单的Button-Command
<ui:GridViewControl x:Name="gridView" Grid.Row="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
<Button HorizontalAlignment="Left" Width="100" Margin="220,0,0,0" Content="Toggle" x:Name="toggleButton" Command="{x:Static ui:GridViewCommands.ToggleSelection}" CommandParameter="{Binding ElementName=gridView}"></Button>
但是如果我启动我的应用程序,GridViewToggleSelectionCommand 中的CanExecute 方法中的parameter-Parameter 始终为空。我的目标是将GridViewControl 的实例作为命令参数传递。
我在这里做错了什么:ui:GridViewCommands.ToggleSelection}" CommandParameter="{Binding ElementName=gridView"}?
编辑
绑定不会抛出任何异常。
非常感谢!
【问题讨论】:
-
您检查绑定是否有错误?如果没有尝试使用 Snoop 这样做。顺便说一句,很棒的应用程序。
-
如果我打开异常抛出或使用这个:stackoverflow.com/a/4226038/2630261 我没有得到任何异常。
标签: c# wpf mvvm command commandparameter