C# 轻触手势事件+;Longlistselector+;组头抽头

C# 轻触手势事件+;Longlistselector+;组头抽头,c#,xaml,windows-phone-8,mvvm-light,longlistselector,C#,Xaml,Windows Phone 8,Mvvm Light,Longlistselector,我正在努力解决一个问题:我有一个长列表选择器,如下所示: <phone:LongListSelector Name="ListContacts" ItemsSource="{Binding GroupedPeople}" JumpListStyle="{StaticResource LongListSelectorJ

我正在努力解决一个问题:我有一个长列表选择器,如下所示:

 <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非常相似:

我的问题是tap事件。当我在一封信中第一次点击时,一切都如期发生。然后,我点击一个联系人查看更多信息,这一切都很好

当我再次单击字母时会出现问题,因为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));

        }
public RelayCommand listcontactstatcommand{get;private set;}
.....
this.ListContactsTapCommand=newrelaycommand(contact=>ShowContactInformation(contact),contact=>contact!=null);
私人void ShowContactInformation(联系人c)
{
ServiceLocator.Current.GetInstance().ContactInfo=c;
_navigationService.NavigateTo(新Uri(ViewModelLocator.ContactInfoPage,UriKind.Relative));
}
我认为可能的解决方案是重置SelectedItem,或者通过一种方式知道我正在点击的位置

有人能帮忙吗? 提前谢谢


“问候”

以一种我并不完全同意的方式解决了我的问题……它稍微“打破”了mvvm模式

这就是我所做的

视图:


视图模型:

 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;

        }
this.ListContactsTapCommand=newrelaycommand(param=>ShowContactInformation(param),param=>param.SelectedItem!=null);
私有void显示联系人信息(LongListSelector c)
{
ServiceLocator.Current.GetInstance().ContactInfo=c.SelectedItem作为联系人;
_navigationService.NavigateTo(新Uri(ViewModelLocator.ContactInfoPage,UriKind.Relative));
c、 SelectedItem=null;
}
我不同意这种方法的原因是因为ViewModel必须从视图中了解对象…这是不应该的,但由于LonglistSelector不允许绑定到SelectedItem,这就是我提供的解决方案

如果你们中有人还有其他观点。。。我很高兴知道:)

提前再次感谢

 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;

        }