我用一些项目创建了Listview.当我点击一个时,我正在导航到新页面.当我按下时,我将回到旧页面(主菜单页面 - >项目页面 - >通过Frame.GoBack()支持主菜单),我看到所有最后点击的项目都是灰色背景.我试图将背景设置为透明,但它不起作用.
在桌面上此问题不存在,背景为黑色. 我正在Windows 10 RS2和Windows 10 Mobile上测试它最后一个内部构建在L640XL.
列表显示:
<ListView Grid.Row="
Name="LineSecondTrackListView"
ItemsSource="{x:Bind _LineSecondTrackBusStops}"
ContainerContentChanging="SetBusStopViewAttribute"
ItemTemplate="{StaticResource BusStopListViewStyle}"
SelectionMode="Single"
SelectionChanged="LineTrackListView_SelectionChangedAsync">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid HorizontalAlignment="Center"
Orientation="Horizontal"
MaximumRowsOrColumns="1"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
Run Code Online (Sandbox Code Playgroud)
我是如何支持的:
public static void BackButtonPressed(object sender, BackRequestedEventArgs e)
{
Frame mainAppFrame = MainFrameHelper.GetMainFrame();
Type currentPageType = mainAppFrame.CurrentSourcePageType;
bool goBack = IsGoBackFromPageAllowed(currentPageType);
if (goBack)
{
mainAppFrame.GoBack();
e.Handled = true;
return;
}
App.Current.Exit();
}
private static bool IsGoBackFromPageAllowed(Type currentPageType)
{
if (currentPageType == typeof(Pages.Lines.LinesViewPage))
return true;
if (currentPageType == typeof(Pages.Lines.LinePage))
return true;
if (currentPageType == typeof(Pages.Lines.LineBusStopPage))
return true;
return false;
}
Run Code Online (Sandbox Code Playgroud)
如何避免这种影响?
编辑
我试过了
foreach (ListViewItem item in LineSecondTrackListView.Items)
VisualStateManager.GoToState(item, "Normal", false); //in the OnNavigatedTo
Run Code Online (Sandbox Code Playgroud)
它不起作用
edit2
在主菜单页面中,当我点击按钮并返回时,此效果保持不变.所有页面都有NavigationCachePage=Required

EDIT3
ButtonListGridView.InvalidateMeasure();
ButtonListGridView.UpdateLayout();
ButtonListGridView.InvalidateArrange();
Run Code Online (Sandbox Code Playgroud)
其中任何一个都没有解决这个问题.
您可以在这里尝试一些事情。我相信您看到的灰色背景PressedBackground是ListViewItemPresenter.
ListView这很可能是 UWP 中的一个计时错误,当选择/按下中的项目时, PressedBackground/PointerOverBackground显示,同时页面 1被缓存并从中清除,Frame然后可以显示页面 2,但应该发生什么缓存之前的问题是,页面1需要完成指针向上/退出动作才能清除PressedBackground/PointerOverBackground颜色,但它未能做到这一点。
要测试这是否是问题的颜色,您所需要做的就是将以下默认值应用于Style您的ItemContainerStyle,ListView并设置PressedBackground="Transparent"or/and PointerOverBackground="Transparent"。
<Style TargetType="ListViewItem">
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}" />
<Setter Property="TabNavigation" Value="Local"/>
<Setter Property="IsHoldingEnabled" Value="True"/>
<Setter Property="Padding" Value="12,0,12,0"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="MinWidth" Value="{ThemeResource ListViewItemMinWidth}"/>
<Setter Property="MinHeight" Value="{ThemeResource ListViewItemMinHeight}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<ListViewItemPresenter
ContentTransitions="{TemplateBinding ContentTransitions}"
SelectionCheckMarkVisualEnabled="True"
CheckBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
CheckBoxBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
DragBackground="{ThemeResource ListViewItemDragBackgroundThemeBrush}"
DragForeground="{ThemeResource ListViewItemDragForegroundThemeBrush}"
FocusBorderBrush="{ThemeResource SystemControlForegroundAltHighBrush}"
FocusSecondaryBorderBrush="{ThemeResource SystemControlForegroundBaseHighBrush}"
PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}"
PointerOverBackground="Transparent"
PointerOverForeground="{ThemeResource SystemControlHighlightAltBaseHighBrush}"
SelectedBackground="{ThemeResource SystemControlHighlightListAccentLowBrush}"
SelectedForeground="{ThemeResource SystemControlHighlightAltBaseHighBrush}"
SelectedPointerOverBackground="{ThemeResource SystemControlHighlightListAccentMediumBrush}"
PressedBackground="Transparent"
SelectedPressedBackground="{ThemeResource SystemControlHighlightListAccentHighBrush}"
DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}"
DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}"
ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
ContentMargin="{TemplateBinding Padding}"
CheckMode="Inline"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
但即使这可能会解决问题,它也会消除有意义的视觉指示。所以让我们尝试一些别的东西 -
在您的LineTrackListView_SelectionChangedAsync方法中,您不是在延迟后立即导航,而是首先取消选择该项目,给它相同的延迟时间以完成取消选择操作,然后进行导航。您需要有一个标志来避免通过更新SelectedItem.
private bool _isWorking;
private async void LineTrackListView_SelectionChangedAsync(object sender, SelectionChangedEventArgs e)
{
if (_isWorking)
{
return;
}
_isWorking = true;
// Removed some of your code here.
listView.SelectedItem = -1;
await Task.Delay(100);
ChangePageToBusPage(selectedBusStopInListView.BusStop, selectedTrack);
_isWorking = false;
}
Run Code Online (Sandbox Code Playgroud)
我没有 Windows Phone,所以无法真正测试代码,但希望它能给您一个想法。祝你好运!