【发布时间】:2018-05-24 19:13:45
【问题描述】:
我有一个 ListView,其中 ListViewItems 有按钮,在 ListView.ItemTemplate 中定义。如何在此类按钮的 Click 事件中选择 ListViewItem?我知道如何在 WPF 中做到这一点,但无法为 UWP 计算,因为 UWP 样式不支持触发器。
【问题讨论】:
标签: uwp
我有一个 ListView,其中 ListViewItems 有按钮,在 ListView.ItemTemplate 中定义。如何在此类按钮的 Click 事件中选择 ListViewItem?我知道如何在 WPF 中做到这一点,但无法为 UWP 计算,因为 UWP 样式不支持触发器。
【问题讨论】:
标签: uwp
在按钮点击事件中添加:
listView.SelectedItem = ((FrameworkElement)sender).DataContext;
【讨论】:
您将不得不使用委托命令
以下示例向您展示如何完成此操作
https://code.msdn.microsoft.com/windowsapps/How-to-bind-command-to-a-299f7759
但一个更简单的例子是使用模板 10,它已经为您创建了一个委托命令。
https://github.com/Windows-XAML/Template10/wiki/MVVM#delegatecommand
要了解有关模板 10 的更多信息,请访问
https://mva.microsoft.com/en-us/training-courses/getting-started-with-template-10-16336
【讨论】: