【发布时间】:2014-03-14 13:10:25
【问题描述】:
我在 ListBox 的 ItemTemplate 中有一个图像,在 Tap 事件上我执行一个动作。
在 ListBox 的 SelectionChanged 事件上,当用户未点击图像时,我导航到另一个页面:我的问题是这些事件的顺序: selectionChanged 事件发生在点击事件之前,然后导航发生在事件点击之前
我该如何解决这个问题?请帮忙
在 selectionChanged 中,我测试它是否不刷新(触发图像 Tap 事件时我设置为 true 的布尔值)我导航到另一个页面,如果它是刷新我不导航
使用 LongListSelector 效果很好,因为先触发点击事件,而不是使用 ListBox(正好是 ReorderListBox)。
我的数据模板包含其他控件:
<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;
}
【问题讨论】:
-
你在做什么改变选择?您的列表框是否仅包含数据模板中的图像或还有其他 UI 元素?.. 请与您的 xaml 分享
-
请参阅编辑@Aman Khandelwal
标签: events windows-phone-8 listbox