本文介绍了[UWP] [C#]无法在ListView上捕获事件SelectedItem到ViewModel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在MasterPage中,有2个Frame。 HomePage位于第一帧 - >
In MasterPage, there are 2 Frame. HomePage is at the first Frame ->
<Page.DataContext>
<viewmodel:HomeVM/>
</Page.DataContext>
<ListView x:Name="lstHome" SelectedItem="{Binding lstHome_ItemClick}"
Margin="10"
ItemsSource="{Binding statusList}">
在HomeVM中:
/// <summary>
/// ItemClick of ListView
/// </summary>
private Status _lstHome_ItemClick;
public Status lstHome_ItemClick
{
get
{
return _lstHome_ItemClick;
}
set
{
if(_lstHome_ItemClick==value)
{
return;
}
_lstHome_ItemClick = value;
//Excute the below code when the selection of listview has changed
ItemClick(_lstHome_ItemClick);
PropertyChanged?.Invoke(this,new PropertyChangedEventArgs("lstHome_ItemClick"));
}
}
public event PropertyChangedEventHandler PropertyChanged;
当我点击Listview上的项目时 - >不要调用lstHome_ItemClick。为什么?
When I click items on Listview-> don't call lstHome_ItemClick. Why?
推荐答案
您只需要将您的绑定更改为牵引方式
You only need to change your Binding to the tow way
SelectedItem="{Binding lstHome_ItemClick,Mode=TwoWay}"
这篇关于[UWP] [C#]无法在ListView上捕获事件SelectedItem到ViewModel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!