[英]Tap gesture event + Longlistselector + Groupheader tap
我正在努力解決以下問題:我有一個LonglistSelector像這樣:
<phone:LongListSelector Name="ListContacts"
ItemsSource="{Binding GroupedPeople}"
JumpListStyle="{StaticResource LongListSelectorJumpListStyle}"
GroupHeaderTemplate="{StaticResource LongListSelectorGroupHeaderTemmplate}"
ItemTemplate="{StaticResource LongListSelectorItemTemplate}"
HideEmptyGroups ="True" IsGroupingEnabled ="true" LayoutMode="List">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Tap">
<mvvmlight:EventToCommand Command="{Binding ListContactsTapCommand, Mode=OneTime}" CommandParameter="{Binding ElementName=ListContacts, Path=SelectedItem}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</phone:LongListSelector>
它在此鏈接中與PeopleHub非常相似: http : //code.msdn.microsoft.com/wpapps/PeopleHub-Windows-Phone-80-88abe94d
我的問題是點擊事件。 當我第一次點擊字母時,一切都會按預期進行。 然后,我點擊一個聯系人以查看更多信息,這也很好。
當我再次單擊字母時會發生問題,因為tap事件被觸發了兩次(我認為):一個是因為SelectedItem不為null,而另一個是顯示字母的。
在我的ViewModel中,我有這個:
public RelayCommand<Contact> ListContactsTapCommand { get; private set; }
.....
this.ListContactsTapCommand = new RelayCommand<Contact>(contact => ShowContactInformation(contact), contact => contact != null);
private void ShowContactInformation(Contact c)
{
ServiceLocator.Current.GetInstance<ContactInfoViewModel>().ContactInfo = c;
_navigationService.NavigateTo(new Uri(ViewModelLocator.ContactInfoPage, UriKind.Relative));
}
我認為可能的解決方案是重置SelectedItem或然后一種方法來知道我在哪里點擊。
誰能幫忙? 提前致謝。
問候
以一種我完全不同意的方式解決了我的問題……並且它“打破”了mvvm模式
這就是我所做的
視圖:
<mvvmlight:EventToCommand Command="{Binding ListContactsTapCommand, Mode=OneTime}" CommandParameter="{Binding ElementName=ListContacts}"/>
ViewModel:
this.ListContactsTapCommand = new RelayCommand<LongListSelector>(param => ShowContactInformation(param), param => param.SelectedItem != null);
private void ShowContactInformation(LongListSelector c)
{
ServiceLocator.Current.GetInstance<ContactInfoViewModel>().ContactInfo = c.SelectedItem as Contact;
_navigationService.NavigateTo(new Uri(ViewModelLocator.ContactInfoPage, UriKind.Relative));
c.SelectedItem = null;
}
我不同意這種方法的原因是因為ViewModel必須從視圖中了解對象……這是不應該的,但是由於LonglistSelector不允許Binding to SelectedItem,所以這是我自帶的解決方案。
如果您有任何其他意見...我將很高興知道:)
再次感謝。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.