c# - 当其他数据绑定(bind)有效时,命令绑定(bind)不起作用

标签 c# wpf data-binding binding wpf-controls

我正在使用 Jarloo's calendar control并对其进行一些更改以满足我的需求。我已经为此苦苦挣扎了很长时间,但我不知道是什么可能导致了我的问题。

所以,我的问题是我的命令绑定(bind)都不起作用。

<ListView Background="White"
          SelectionMode="Single"
          dd:DragDrop.DropHandler="{Binding}" 
          dd:DragDrop.IsDropTarget="True"
          dd:DragDrop.UseDefaultDragAdorner="True" 
          ItemsSource="{Binding Typologies}" 
          IsEnabled="{Binding Enabled}">
    <ListView.InputBindings>
        <KeyBinding Key="Delete" Command="{Binding CancelDispatchCommand}" CommandParameter="{Binding SelectedItem}"/>
    </ListView.InputBindings>
....
</ListView>

在这里,键绑定(bind)不起作用,但 {Binding Typologies} 和其他数据绑定(bind)都运行良好。这让我认为这不是数据上下文问题。

<Button DockPanel.Dock="Left" Margin="0,0,10,0" Content="&lt;&lt;" Command="{Binding ChangeDateCmd}" CommandParameter="YEAR,PREV"/>

在这里,我的命令绑定(bind)在这时根本不起作用:

<TextBlock Padding="5" Text="{Binding TargetDate, Converter={StaticResource DateConverter}, ConverterParameter=MONTH}"/>

工作得很好......

在 day.cs 中:

private ICommand cancelDispatchCommand;
public ICommand CancelDispatchCommand
{
    get
    {
        return cancelDispatchCommand = cancelDispatchCommand ?? new ActionCommand((o) => CancelDispatch(o));
    }
}

在 calendar.cs 中:

ICommand changeDateCmd;
public ICommand ChangeDateCmd
{
    get
    {
        return changeDateCmd = changeDateCmd ?? new ActionCommand((o) => ChangeDate(o));
    }
}

最佳答案

您不需要将 {Binding } 与命令名称一起使用。

Here是一个例子

关于c# - 当其他数据绑定(bind)有效时,命令绑定(bind)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31142970/

相关文章:

WPF Grid/WrapPanel 自动调整大小动画

WPF:列表中删除命令的命令参数

c# - Xamarin 在哪里执行绑定(bind)表达式?

c# - 为什么 XmlSerializer 抛出 InvalidOperationException?

wpf - 我需要知道演示模型中的窗口句柄

wpf - 为什么我不能在样式内设置数据模板,但可以在控件模板内设置?

c# - 将时间跨度绑定(bind)到 slider

c# - Aspnet core 2.1.4 IIS启动问题

c# - 通过数据键名获取 Gridview 行

c# - 我想在列表中获取 Windows Phone 7 中的所有联系人