【发布时间】:2017-10-11 18:54:05
【问题描述】:
我需要使用 MVVM 在 UWP 中通过鼠标双击 ListView 打开一个新视图(项目详细信息)。在 WPF 中,我使用了带参数的命令和 EventTrigger,但微软不建议在 UWP 中使用它:
触发器、EventTrigger、Actions 和 BeginStoryboard 并不常用。这些 API 主要存在于最初用于 Microsoft Silverlight 的 XAML 中的兼容性...对于控件模板中的事件,请使用视觉状态和 VisualStateManager。
据我了解,当您需要更改控件的视觉状态但我需要打开一个新视图时使用它。
我怎样才能将VisualStateManager 用于我的目的?
这就是我的 XAML 在 WPF 中的样子:
<ListBox x:Name="PersonsListControl" Grid.RowSpan="3" Grid.Row="0" Grid.Column="2"
ItemsSource="{Binding Path=PersonsProvider}"
ItemsPanel="{StaticResource PersonsListPanelTemplate}"
ItemTemplate="{StaticResource PersonsListItemTemplate}"
SelectedItem="{Binding SelectedPerson}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<i:InvokeCommandAction
Command="{Binding GetPersonDetailsCommand}"
CommandParameter="{Binding SelectedPerson}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ListBox>
【问题讨论】:
标签: c# listview events mvvm uwp