2016-10-31 2 views
0

Je cette ListView:Comment changer la couleur de l'élément listview

<Page.Resources> 

<DataTemplate x:Key="ListItemTemplate"> 
    <TextBlock 
     Text="{Binding Name}" 
     Style="{ThemeResource ListViewItemStyle}" 
     /> 

<ListView 
x:Name="myListView" 
ItemsSource="{Binding}" 
ItemTemplate="{StaticResource ListItemTemplate}" 
> 

Comment changer la couleur de ListViewItem sélectionné?

Répondre

0

Pour changer la couleur sélectionnée pour le ListViewItem dans le ListView, nous avons besoin de modifier son style comme suit:

S'il vous plaît clic droit sur le contrôle ListView ->Modifier les modèles supplémentaires ->Modifier Generated Container article (ItemContainerStyle) ->Modifier une copie: enter image description here Ensuite, vous obtiendrez le XAML et s'il vous plaît modifier cette SelectedBackground propriété suivante dans la ListViewI temPresenter à une couleur que vous aimez comme suit:

<DataTemplate x:Key="ListItemTemplate"> 
     <TextBlock Text="{Binding name}" /> 
    </DataTemplate> 
    <Style x:Key="ListViewItemStyle1" TargetType="ListViewItem"> 
     <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/> 
     <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/> 
     <Setter Property="Background" Value="{ThemeResource ListViewItemBackground}"/> 
     <Setter Property="Foreground" Value="{ThemeResource ListViewItemForeground}"/> 
     <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="AllowDrop" Value="False"/> 
     <Setter Property="UseSystemFocusVisuals" Value="True"/> 
     <Setter Property="FocusVisualMargin" Value="0"/> 
     <Setter Property="FocusVisualPrimaryBrush" Value="{ThemeResource ListViewItemFocusVisualPrimaryBrush}"/> 
     <Setter Property="FocusVisualPrimaryThickness" Value="2"/> 
     <Setter Property="FocusVisualSecondaryBrush" Value="{ThemeResource ListViewItemFocusVisualSecondaryBrush}"/> 
     <Setter Property="FocusVisualSecondaryThickness" Value="1"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="ListViewItem"> 
        <ListViewItemPresenter CheckBrush="{ThemeResource ListViewItemCheckBrush}" ContentMargin="{TemplateBinding Padding}" CheckMode="{ThemeResource ListViewItemCheckMode}" ContentTransitions="{TemplateBinding ContentTransitions}" CheckBoxBrush="{ThemeResource ListViewItemCheckBoxBrush}" DragForeground="{ThemeResource ListViewItemDragForeground}" DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}" DragBackground="{ThemeResource ListViewItemDragBackground}" DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}" FocusVisualPrimaryBrush="{TemplateBinding FocusVisualPrimaryBrush}" FocusVisualSecondaryThickness="{TemplateBinding FocusVisualSecondaryThickness}" FocusBorderBrush="{ThemeResource ListViewItemFocusBorderBrush}" FocusVisualMargin="{TemplateBinding FocusVisualMargin}" FocusVisualPrimaryThickness="{TemplateBinding FocusVisualPrimaryThickness}" FocusSecondaryBorderBrush="{ThemeResource ListViewItemFocusSecondaryBorderBrush}" FocusVisualSecondaryBrush="{TemplateBinding FocusVisualSecondaryBrush}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Control.IsTemplateFocusTarget="True" PointerOverForeground="{ThemeResource ListViewItemForegroundPointerOver}" PressedBackground="{ThemeResource ListViewItemBackgroundPressed}" PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackground}" PointerOverBackground="{ThemeResource ListViewItemBackgroundPointerOver}" ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}" SelectedPressedBackground="{ThemeResource ListViewItemBackgroundSelectedPressed}" SelectionCheckMarkVisualEnabled="{ThemeResource ListViewItemSelectionCheckMarkVisualEnabled}" SelectedForeground="Red" SelectedPointerOverBackground="{ThemeResource ListViewItemBackgroundSelectedPointerOver}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" 
SelectedBackground="Red"/> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
</Page.Resources> 
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
    <ListView x:Name="myListView" ItemTemplate="{StaticResource ListItemTemplate}" ItemContainerStyle="{StaticResource ListViewItemStyle1}"/> 
</Grid>