locked
How to change the visibility of SelectedCheckMark in the selected item of a listview

    Question

  • Hi everybody,

    Can somebody help me with this? I'm using a Listview to display some data, but I don't really like the way the selected item looks.

    I figured out a way to change the colours but I want to get rid off the checkmark as well. Is there any way to do that?

    Thanks in advance.

    Sunday, November 30, 2014 7:08 AM

Answers

  • You must modify the template of the ListViewItem to get rid of the selection mark.

    Right-click on the ListView in design mode in Visual Studio and choose "Edit Additional Templates"->"Edit Generated Item Container (ItemContainerStyle)"->"Edit a Copy". This will copy the default control template to a location of your choice. You can then simply set the SelectionCheckMarkVisualEnabled property of the ListViewItemPresenter in the default control template to false. Here is an example:

    <Page.Resources>
            <Style x:Key="ListViewItemStyle1" TargetType="ListViewItem">
                <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/>
                <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/>
                <Setter Property="Background" Value="Transparent"/>
                <Setter Property="TabNavigation" Value="Local"/>
                <Setter Property="IsHoldingEnabled" Value="True"/>
                <Setter Property="Margin" Value="0,0,18,2"/>
                <Setter Property="HorizontalContentAlignment" Value="Left"/>
                <Setter Property="VerticalContentAlignment" Value="Top"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ListViewItem">
                            <ListViewItemPresenter CheckHintBrush="{ThemeResource ListViewItemCheckHintThemeBrush}" 
                                                   CheckBrush="{ThemeResource ListViewItemCheckThemeBrush}" 
                                                   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="False" 
                                                   SelectedForeground="{ThemeResource ListViewItemSelectedForegroundThemeBrush}"
                                                   SelectedPointerOverBackground="{ThemeResource ListViewItemSelectedPointerOverBackgroundThemeBrush}" 
                                                   SelectedBorderThickness="{ThemeResource ListViewItemCompactSelectedBorderThemeThickness}" 
                                                   SelectedBackground="{ThemeResource ListViewItemSelectedBackgroundThemeBrush}" 
                                                   VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Page.Resources>

    <ListView x:Name="lv" ItemContainerStyle="{StaticResource ListViewItemStyle1}">
    
            </ListView>
    

    Hope it helps.

    Please remember to mark helpful posts as answer and/or helpful.

    • Marked as answer by giannisdolon Sunday, November 30, 2014 10:27 PM
    Sunday, November 30, 2014 7:42 PM

All replies

  • You must modify the template of the ListViewItem to get rid of the selection mark.

    Right-click on the ListView in design mode in Visual Studio and choose "Edit Additional Templates"->"Edit Generated Item Container (ItemContainerStyle)"->"Edit a Copy". This will copy the default control template to a location of your choice. You can then simply set the SelectionCheckMarkVisualEnabled property of the ListViewItemPresenter in the default control template to false. Here is an example:

    <Page.Resources>
            <Style x:Key="ListViewItemStyle1" TargetType="ListViewItem">
                <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/>
                <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/>
                <Setter Property="Background" Value="Transparent"/>
                <Setter Property="TabNavigation" Value="Local"/>
                <Setter Property="IsHoldingEnabled" Value="True"/>
                <Setter Property="Margin" Value="0,0,18,2"/>
                <Setter Property="HorizontalContentAlignment" Value="Left"/>
                <Setter Property="VerticalContentAlignment" Value="Top"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ListViewItem">
                            <ListViewItemPresenter CheckHintBrush="{ThemeResource ListViewItemCheckHintThemeBrush}" 
                                                   CheckBrush="{ThemeResource ListViewItemCheckThemeBrush}" 
                                                   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="False" 
                                                   SelectedForeground="{ThemeResource ListViewItemSelectedForegroundThemeBrush}"
                                                   SelectedPointerOverBackground="{ThemeResource ListViewItemSelectedPointerOverBackgroundThemeBrush}" 
                                                   SelectedBorderThickness="{ThemeResource ListViewItemCompactSelectedBorderThemeThickness}" 
                                                   SelectedBackground="{ThemeResource ListViewItemSelectedBackgroundThemeBrush}" 
                                                   VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Page.Resources>

    <ListView x:Name="lv" ItemContainerStyle="{StaticResource ListViewItemStyle1}">
    
            </ListView>
    

    Hope it helps.

    Please remember to mark helpful posts as answer and/or helpful.

    • Marked as answer by giannisdolon Sunday, November 30, 2014 10:27 PM
    Sunday, November 30, 2014 7:42 PM
  • Thank you, this is exactly what I was looking for. Much appreciated.

    Sunday, November 30, 2014 10:28 PM