2017-03-23 4 views
6

enter image description hereListViewItemの壊れた背景をUWPで削除するには?

I一部のアイテムでリストビューを作成しました。 1つをクリックすると、新しいページに移動します。 私は前のページに戻ります(メインメニューページ - >アイテムページ - >メインメニューへの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> 

どのようにバックアップしています:

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

この影響を避けるために、どのように?

編集

私は

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

にしようと、それはメインメニューページで

EDIT2 仕事doesntの、私はボタンでクリックして戻って行った時、この効果はとどまります。すべてのページは、これらのいずれかがそれを修正しなかったNavigationCachePage=Required main menu

EDIT3

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

を持っています。

+0

Background =#00FFFFFF – lindexi

+1

NavigationCacheMode.EnabledまたはNavigationCacheMode.Requiredを使用してページをキャッシュしていますか?私は自分のアプリで同じ問題を抱えていますが、解決策はありません。 :/ –

+0

おそらくforeach(LineSecondTrackListView.ItemsのListViewItem項目)を使用しています。VisualStateManager.GoToState(item、 "Normal"、false); OnNavigatedToメソッドのオーバーライドが役に立ちます。 (テストされていないので、数分前にこのアイデアを得ました。) –

答えて

2

ここで試してみてください。私はの灰色の背景がのListViewItemPresenterであると信じています。

それはListViewのアイテムが選択された場合/、PressedBackground/PointerOverBackgroundショーを押し、同時にページ1がどのFrameからキャッシュされ、クリアされている可能性が最も高いUWPのタイミングバグですその後、2ページを表示するが、どのようなキャッシングの前に起こるべきことはページ1は、それがそうする失敗しPressedBackground/PointerOverBackground色を、クリアするためにポインターアップ/終了アクションを完了する必要があるということであることができます。それは、問題の色だかどうかをテストするために

、あなたが必要とするすべてはあなたのListViewのごItemContainerStyleに以下のデフォルトStyleを適用することで、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を持っていないので、コードを実際にテストすることはできませんが、うまくいけばアイデアが得られます。がんばろう!

+1

どのような作品ですか? スタイルは私のために働いていましたが、選択したアイテムをリセットするページを変更する前に追加する必要がありました。そして... Task.Delayを100から250に変更しました。 ありがとう、幸せなコード作成:) – Niewidzialny

0

あなたのリストビューでは、onclick/onselectイベントを処理し、アイテムをUnselectedに設定します。

+0

を持って、私は左に、選択したすべてのアイテムが欲しい – Niewidzialny

関連する問題