c# - DataTemplate 中的 Command- 和 InputBindings
问题描述
我有一个 WPF UserControl,我试图用一种 MVVM 模式来适应我的程序。现在的问题是,UserControl 使用了我不能简单地应用于 DataTemplate 的 Command- 和 InputBindings。在没有代码隐藏的情况下,我必须有哪些选项来实现相同的功能?
这是目前的 XAML:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyProject.Settings"
xmlns:elements="clr-namespace:MyProject.Settings.Elements"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:dataPresenter="http://infragistics.com/DataPresenter"
xmlns:igEditors="http://infragistics.com/Editors"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity">
<DataTemplate x:Key="PrioritySettingTemplate" DataType="{x:Type elements:PrioritySetting}">
<ContentPresenter>
<ContentPresenter.InputBindings>
<KeyBinding Gesture="Delete" Key="Delete"
Command="{Binding TestCommand}" />
</ContentPresenter.InputBindings>
<ContentPresenter.ContentTemplate>
<DataTemplate DataType="{x:Type elements:PrioritySetting}">
<!--
Main part of the UserControl
-->
</DataTemplate>
</ContentPresenter.ContentTemplate>
</ContentPresenter>
</DataTemplate>
解决方案
推荐阅读
- angular - 在 ngFor Angular 上按 start_date 排序
- c# - 数据下载 无需在前端加载数据
- android - 列表视图达到特定整数后如何弹出对话框?
- flutter - 找不到正确的提供者
在带有导航流的 Flutter 中这个 Y 小部件上方 - uwp - 如何重新连接到 BLE 设备?- UWP
- flutter - 颤振中带有多选芯片的警报框
- maven - gradle 不是像 Maven 有 m2 那样有自己的仓库吗?
- python - Python:屏蔽电子邮件文本中的命名实体
- javascript - 如果尚未下载脚本,则跳过同步脚本执行
- reactjs - react-native:如何隐藏底部标签栏 onPress