How to remove broken ListViewItem background in UWP?

enter image description here

I created a list with some elements. When I click on one, I go to a new page. When I go back, I will go back to the old page (Main menu page β†’ page with elements β†’ in the main menu using Frame.GoBack ()) and I see that all the last pressed elements have a gray background. I tried to set the background to transparent, it does not work.

On the desktop, this problem does not exist, the background is black. I am testing it on Windows 10 RS2 and Windows 10 Mobile for the latest insider build on the L640XL.

Listview

<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>

How I support:

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;
}

How to avoid this effect?

Edit

I tried using

foreach (ListViewItem item in LineSecondTrackListView.Items) 
    VisualStateManager.GoToState(item, "Normal", false); //in the OnNavigatedTo 

and it does not work

edit2 On the main menu page, when I pressed the button and returned, this effect remains. All pages haveNavigationCachePage=Required Main menu

Edit3

ButtonListGridView.InvalidateMeasure();
ButtonListGridView.UpdateLayout();
ButtonListGridView.InvalidateArrange();

.

+6
2

, . , , , PressedBackground ListViewItemPresenter.

, UWP , ListView /, PressedBackground/PointerOverBackground, 1 Frame, 2, , , 1 /, PressedBackground/PointerOverBackground , .

, , Style ItemContainerStyle ItemContainerStyle ListView PressedBackground="Transparent" / 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>

, . , - -

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;
}

Windows Phone, , , , . !

+2

onclick/onselect Unselected.

0

Source: https://habr.com/ru/post/1015982/


All Articles