3

I've searched an answer to this simple question but didn't find a solution yet. I have the following code:

<Grid>
    <Border BorderBrush="#666666" BorderThickness="1,1,1,1" CornerRadius="3">
        <Border.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FF020f1e" Offset="0"/>
                <GradientStop Color="#FF484F58" Offset="1"/>
            </LinearGradientBrush>
        </Border.Background>
        <ListView Name="lvUsers" Background="Transparent" Foreground="White" Margin="3" FontSize="12" SelectionChanged="lvUsers_SelectionChanged">
            
            <ListView.Template>
                <ControlTemplate TargetType="{x:Type ListView}">
                    <Border CornerRadius="1" BorderThickness="1" BorderBrush="Transparent">
                        <ScrollViewer>
                            <ItemsPresenter />
                        </ScrollViewer>
                    </Border>
                </ControlTemplate>
            </ListView.Template>

            <ListView.View>
                <GridView>

                    <GridView.Columns>
                        <GridViewColumn>
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <CheckBox Tag="{Binding ID}" IsChecked="{Binding IsChecked}" Checked="CheckBox_CheckedChanged" Unchecked="CheckBox_CheckedChanged" IsHitTestVisible="False" Focusable="False"/>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn DisplayMemberBinding="{Binding ID}" Header="ID" />
                        <GridViewColumn DisplayMemberBinding="{Binding Name}" Header="Name" />
                    </GridView.Columns>
                </GridView>                  
            </ListView.View>

            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <EventSetter Event="PreviewMouseLeftButtonDown" Handler="ListViewItem_PreviewMouseLeftButtonDown" />

                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="Background" Value="Transparent"/>

                        </Trigger>
                        <Trigger Property="IsSelected"  Value="true">
                            <Setter Property="Background" Value="Transparent"/>
                            <Setter Property="BorderBrush"  Value="Black"/>
                        </Trigger>

                    </Style.Triggers>
                </Style>
            </ListView.ItemContainerStyle>
        </ListView>
    </Border>
</Grid>

that results in the following effect when I select or "mouse over" a row:

MyApplication

MyApplication

I want to remove that glossy effect and obtain exactly the style of a plain "ListView":

Target Application

Target Application

Can you tell me the easiest way to achive this?

Thank you very much

Albert Einstein
  • 7,472
  • 8
  • 36
  • 71
Enrico
  • 45
  • 9

2 Answers2

3

ListViewItem has some fancy triggers in its Template (Controltemplate.Triggers) which change background under some conditions (e.g. for selected items). To remove them set a simplified Template, without triggers:

<Style TargetType="ListViewItem">
<Setter Property="Template">
    <Setter.Value>
        <ControlTemplate TargetType="{x:Type ListViewItem}">
            <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" 
                    BorderThickness="{TemplateBinding BorderThickness}" 
                    Background="{TemplateBinding Background}" 
                    Padding="{TemplateBinding Padding}"
                    SnapsToDevicePixels="true">
                <GridViewRowPresenter 
                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
            </Border>
        </ControlTemplate>
    </Setter.Value>
</Setter>
<Style.Triggers> 
<!-- your triggers for IsMouseOver and IsSelected -->
</Style.Triggers> 
ASh
  • 34,632
  • 9
  • 60
  • 82
0

You are obviously using some custom style that provides this effect.

You could try to set the Style property of the ListView to {x:Null} to use the default style:

<ListView Style="{x:Null}" Name="lvUsers" Background="Transparent" Foreground="White" Margin="3" FontSize="12" SelectionChanged="lvUsers_SelectionChanged">
...
mm8
  • 163,881
  • 10
  • 57
  • 88