ListBox SelectionChanged和Image Tap事件订单

时间:2014-03-14 13:10:25

标签: events windows-phone-8 listbox

我在ListBox的ItemTemplate中有一个图像,在Tap事件上执行一个动作。

在ListBox的SelectionChanged事件上当用户没有点击图像时,我导航到另一个页面:我的问题是这些事件的顺序:selectionChanged事件发生在点击事件之前,然后导航发生在事件之前Tap

我该如何解决这个问题?请帮忙

在selectionChanged中我测试它是否不刷新(当图像点击事件触发时我设置为true的布尔值)我导航到另一个页面,如果它是刷新我不导航

使用LongListSelector它可以很好地工作,因为tap事件是先触发但不是ListBox(精确的ReorderListBox)。

我的datatemplate包含其他控件:

   <DataTemplate x:Key="ItemTemplate" >
        <Grid Height="150" Width="408" Background="White" Margin="0,0,0,14">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <toolkit:ContextMenuService.ContextMenu  >
                <toolkit:ContextMenu Height="150" Background="#26AA99" BorderBrush="Transparent"  Unloaded="ContextMenu_Unloaded"  >
                    <toolkit:MenuItem Header="{Binding Path=LocalizedResources.PinToStart, Source={StaticResource LocalizedStrings}}"   Foreground="#FFFFFF" FontWeight="Normal" FontSize="26" Click="MIPinSchedule_Click"   />
                    <toolkit:MenuItem Header="{Binding Path=LocalizedResources.Delete, Source={StaticResource LocalizedStrings}}"    Foreground="#FFFFFF" FontWeight="Normal" FontSize="26" Click="MIDeleteSchedule_Click"   />
                </toolkit:ContextMenu>
            </toolkit:ContextMenuService.ContextMenu>
            <Border Grid.Row="0" Background="{Binding LineColor}" Height="14" Width="408"/>
            <TextBlock Text="{Binding Name}" VerticalAlignment="Center" Margin="12,0,0,0" Foreground="#00418D" FontWeight="SemiBold" FontSize="26"/>

        <Grid   >
            <!--Les deux prochais passages-->
            <phone:LongListSelector 
                            ItemsSource="{Binding NextStopCollection, Mode=TwoWay}"
                            LayoutMode="List"                                          
                            ItemTemplate="{StaticResource ItemTemplate2}" />
            <!--Boutton refresh qui s'affiche au bout de 20 secondes-->
            <Image  VerticalAlignment="Center" Margin="0,0,12,0" HorizontalAlignment="Right"   Height="48" Width="48" 
                           Source="/Assets/Refresh.png" Tap="Refresh_Tap" 
                           Visibility="{Binding  ElementName=reorderListBox, Path=DataContext.IsOutOfDate,Converter={StaticResource BooleanToVisibilityConverter}}"/>
        </Grid>
        </Grid>
    </DataTemplate>


private void reorderListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        var rlb = sender as ReorderListBox.ReorderListBox;
        if (rlb.SelectedItem == null)
            return;
        if (!viewModel._isRefresh)
        {
            var selectedItem = rlb.SelectedItem as MyObject;

            NavigationService.Navigate(new Uri(MyUri, UriKind.Relative));

        }

        _isRefresh = false;
        rlb.SelectedItem = null;
    }

 private void Refresh_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
       //Do action
        _isRefresh = true;
    }

1 个答案:

答案 0 :(得分:1)

我建议您完全放弃SelectionChanged事件,而是在Tap的{​​{1}}上添加Grid个事件。