I'm struggling with a problem which is: I have a LonglistSelector like this:
<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>
It is very similar to the PeopleHub in this link: http://code.msdn.microsoft.com/wpapps/PeopleHub-Windows-Phone-80-88abe94d
My problem is with the tap event. When I tap the first time in a letter all happens as expected. Then, I tap on a contact to see more information, and it's all good as well.
The problem happens when I click again on the letter, because the tap event is fired twice (I think): one because SelectedItem is not null and other to show the letter's.
In my ViewModel I have this:
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));
}
What I think could be the solution is to reset SelectedItem or then a way to know where I'm tapping.
Can anyone give a hand? Thanks in advance.
Regards
Solved my problem in a way I don't fully agree...and it "breaks" mvvm pattern a little
This is what I've done
View:
ViewModel:
The reason I don't agree this approach is because ViewModel will have to know objects from view...which is not supposed, but since LonglistSelector doesn't allow Binding to SelectedItem this was the solution I came with.
If any of you have any other point... I'll be glad to know it :)
Thanks again in advance.