【发布时间】:2015-09-17 12:39:15
【问题描述】:
我正在使用Jarloo's calendar control 并在其上添加一些更改以满足我的需求。我已经为此苦苦挣扎了很长时间,但我不知道我的问题可能是什么原因。
所以,我的问题是我的 Command 绑定都不起作用。
<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>
在这里,键绑定不起作用,但 {Binding Typologies} 和其他 DATA 绑定都运行良好。这让我认为这不是数据上下文问题。
<Button DockPanel.Dock="Left" Margin="0,0,10,0" Content="<<" Command="{Binding ChangeDateCmd}" CommandParameter="YEAR,PREV"/>
在这里,我的命令绑定根本不起作用:
<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));
}
}
【问题讨论】:
-
尝试RelativeSource AncestorType ListView 并使用它的DataContext 并告诉它是否工作正常。
-
@Maximus 对不起,我忘了说我已经试过了......这也不好用:
<KeyBinding Key="Delete" Command="{Binding DataContext.CancelDispatchCommand, RelativeSource={RelativeSource AncestorType=ListView}}" CommandParameter="{Binding SelectedItem}"/>:( -
输出窗口有错误吗?
-
@Maximus 好吧,谢谢...显然问题出在它无法加载 Microsoft.Expressions.Interactions 4.5 所以我不得不降级对 4.0 版本的引用 ....
标签: c# wpf data-binding binding wpf-controls