2011-08-22 113 views
1

似乎没有在windows phone的ListBox中7.0,因为在7.1
点击事件处理我发现的SelectionChanged事件然而这个事件引起的问题。那么,在7.0中点击不同的事件?点击事件处理程序

private void flightlist_SelectionChanged(object sender, SelectionChangedEventArgs e) 
{  
PhoneApplicationService.Current.State["Flight"] = flightlist.SelectedItem;  
NavigationService.Navigate(new Uri("/FlightDetail", UriKind.Relative));  
} 

回答

5

Silverlight Toolkit有GestureListener,让您柄敲击,DoubleTap,还有更多的事件。

它可以附加任何元素。但无论如何,使用自定义的tap处理程序,SelectionChanged事件的用途是一个愚蠢的想法。你应该澄清为什么它会为你“造成问题”。

更新

修改代码以这样的:

private void flightlist_SelectionChanged(object sender, SelectionChangedEventArgs e) 
{  
    if (flightlist.SelectedItem != null) 
    { 
     PhoneApplicationService.Current.State["Flight"] = flightlist.SelectedItem; 
     NavigationService.Navigate(new Uri("/FlightDetail", UriKind.Relative)); 
    } 

    // reset the selected-index, so the user can click on it again, after returning. 
    flightlist.SelectedIndex = -1; 
} 
+0

的问题:被选择后,我想导航到另一个页面,我可以这样做。 但是,如果我按回退按钮回到我从整个应用程序导航崩溃并存在的页面。 – Ameen

+0

这将是因为你的代码没有正确的墓碑。它不一定与ListBox或SelectionChanged事件相关(显示一些代码!)。此外,如果用户单击后退按钮时应用程序崩溃,您的应用程序将无法通过验证。 –

+0

当我在7.1中使用Tap事件时,问题不再发生。我做了测试,似乎在点击后退按钮后,事件再次被触发,导致导航到第二页,然后读取一个空变量,从而引发异常。选择代码显示在上面的问题中。 – Ameen

-1

您可以使用ListBox的MouseLeftButtonUp事件,然后获取所选项目(如果有的话)。示例代码:

private void YourListBox_LeftMouseButtonUp(object sender, MouseButtonEventArgs e) 
{ 
    var listBox = sender as ListBox; 
    var item = listBox.SelectedItem; 
    if (item != null) 
    { 
     //do something with the item 
    } 
} 
+0

谢谢哥们,对不起,但需要采取最好的答案:)发生在这种情况下 – Ameen

相关问题