UWP:如何从视图模型中的另一个列表视图中捕获一个列表视图部件的单击,而不是在代码后方单击? [英] UWP: How to catch the click of a listview part from another listview in the viewmodel instead of code-behind?
问题描述
我有此列表视图:
<Page
x:Class="DataBase.ControlsPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
DataContext="{Binding CustomersViewModel, Source={StaticResource ViewModelLocator}}">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ListView Name="HeaderList" ItemsSource="{Binding Customers}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Border Background="Bisque">
<TextBlock Text="{Binding Name"/>
</Border>
<ListView Name="SubItemsList" ItemsSource="{Binding Project}" ItemClick="SubItemClick">
<x:String>SubItem 1</x:String>
<x:String>SubItem 2</x:String>
<x:String>SubItem 3</x:String>
</ListView>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<x:String>Item 1</x:String>
<x:String>Item 2</x:String>
<x:String>Item 3</x:String>
</ListView>
</Grid>
</Page>
我只想在我的CustomersViewModel中捕获一个subItem( ItemClick ="SubItemClick"> )的点击.那可能吗?我知道对于子项列表项,数据是一个Project,它只是一个数据模型,它不包含任何单击处理程序.但是,如何在视图模型中而不是在代码隐藏中捕获点击?
All I want is to catch the click of a subItem(ItemClick="SubItemClick">) in my CustomersViewModel. Is that possible? I know for the sub-items list items, the data is a Project which is just a data model, it does not contain any click handler. But, how can I catch the click in the view model and not in the code-behind?
我也正在上传图片以可视化我想要的东西:
Also I'm uploading a picture to visualise what I want:
推荐答案
正如Justin XL所说,我一直在寻找的答案是:
ItemClick="{Binding DataContext.ClickCommand, ElementName=HeaderList}"
As Justin XL said, the answer I was looking for is this:
ItemClick="{Binding DataContext.ClickCommand, ElementName=HeaderList}"
这篇关于UWP:如何从视图模型中的另一个列表视图中捕获一个列表视图部件的单击,而不是在代码后方单击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!