none
请问如何更改ListView选中行颜色 RRS feed

  • 问题

  • 我的控件模板如下。

    <Style x:Key="ListViewKnowledgeSystemDiagramStyles" TargetType="ListView">
            <Setter Property="Background" Value="{ThemeResource ForegroundColorBrush}"/>
            <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden"/>
            <Setter Property="HorizontalContentAlignment" Value="Left"/>
            <Setter Property="Padding" Value="0"/>
            <Setter Property="Margin" Value="0"/>
            <Setter Property="ItemContainerStyle">
                <Setter.Value>
                    <Style TargetType="ListViewItem">
                        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                        <Setter Property="VerticalContentAlignment" Value="Stretch"/>
                        <Setter Property="Margin" Value="0"/>
                        <Setter Property="Padding" Value="0"/>
                        <!--<Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="ListViewItem">
                                    <ListViewItemPresenter CheckHintBrush="{ThemeResource ListViewItemCheckHintThemeBrush}" CheckBrush="White" ContentMargin="4" ContentTransitions="{TemplateBinding ContentTransitions}" CheckSelectingBrush="{ThemeResource ListViewItemCheckSelectingThemeBrush}" DragForeground="{ThemeResource ListViewItemDragForegroundThemeBrush}" DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}" DragBackground="{ThemeResource ListViewItemDragBackgroundThemeBrush}" DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}" FocusBorderBrush="{ThemeResource ListViewItemFocusBorderThemeBrush}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" PointerOverBackgroundMargin="1" PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" PointerOverBackground="{ThemeResource ListViewItemPointerOverBackgroundThemeBrush}" ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}" SelectedPointerOverBorderBrush="{ThemeResource ListViewItemSelectedPointerOverBorderThemeBrush}" SelectionCheckMarkVisualEnabled="True" SelectedForeground="{ThemeResource ListViewItemSelectedForegroundThemeBrush}" SelectedPointerOverBackground="{ThemeResource ListViewItemSelectedPointerOverBackgroundThemeBrush}" SelectedBorderThickness="{ThemeResource ListViewItemCompactSelectedBorderThemeThickness}" SelectedBackground="{ThemeResource ListViewItemSelectedBackgroundThemeBrush}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>-->
                    </Style>
                </Setter.Value>
            </Setter>
            <Setter Property="ItemTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <Border BorderBrush="White" BorderThickness="0,0,0,1">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="10"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="50"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Image Source="{Binding ImageSource}" Stretch="Fill" Width="50" Height="50" x:Name="Image" Grid.Row="0" Grid.RowSpan="2" Grid.Column="0"/>
    
                                <TextBlock FontSize="12" Text="{Binding Title}" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Top" TextWrapping="WrapWholeWords" Grid.Row="0" Grid.Column="1" />
    
                                <TextBlock FontSize="8" Text="{Binding SubTitle}" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5,0,0,0" TextWrapping="WrapWholeWords" Grid.Row="1" Grid.Column="1"/>
                            </Grid>
                        </Border>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    请问,怎么在ItemContainerStyle中,更改ListView选中行的的背景色?

    2015年8月5日 11:54

答案

  • Hello FreestyleSago,

    >>请问,怎么在ItemContainerStyle中,更改ListView选中行的的背景色?

    把被你注释掉那部分代码替换成用UIElement tree and visual states的模板:

    https://msdn.microsoft.com/en-us/library/windows/apps/xaml/JJ709921.aspx

    selected的状态下,修改选中项的模板。

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • 已标记为答案 Sago.Su 2015年8月11日 1:37
    2015年8月6日 2:20
    版主

全部回复