Search code examples
c#xamlwindows-phone-7listboxselectionchanged

Touch issue on ListBox


I have this ListBox in my xaml.

FIRST.XAML

<ListBox ItemsSource="{Binding Items}" x:Name="newsList" 
   ItemTemplate="{StaticResource NewsListTemplate}"
   Margin="-2,86,2,0" SelectionChanged="openNewsViewer" 
   Height="361" VerticalAlignment="Top" d:LayoutOverrides="GridBox"
/>

The problem is that when I click first time on a list item, all ok, it calls SECOND.XAML correctly, but, when I go back to FIRST.XAML from SECOND.XAML, I'm unable to re-click at the same ListBox item!

But why?

Here C# code:

private void openNewsViewer(object sender, SelectionChangedEventArgs e)
{
    var listbox = (ListBox)sender;
    var entry = (ItemViewModel)listbox.SelectedItem;

    Navigate(entry.Link, entry.LineOne, true);
}

private void Navigate(string url, string title, bool showAppBar)
{
    var uri = "/NewsViewer.xaml?idx=" + url + "&title=" + title + "&appbar=" + (showAppBar == true ? "true" : "false");
    NavigationService.Navigate(new Uri(uri, UriKind.Relative));
}

It's all!

Any idea to solve this issue?
Thanks!

EDIT 1:
Second click on the same row NOT CALL openNewsViewer. It could be a problem in XAML file?

Please help me.
thanks^2!


Solution

  • The problem is that your event fires when page is reloaded ( when your listbox is created the selectedItem is changed).

    You can use ManipulationStarted event.