views:

22

answers:

1

I already tried for whole day, getting mad.

I have a ListView, with ListView.View as GridView.

Default, the mouseOver is working, ListViewItem get highlighted when I mouseover, and get selected when I click it. But after I modified the ControlTemplate, I get the template I want, but the highlight and select is gone.

I use trigger, but it's not working.

Here is my code.

<Style x:Key="filesListViewItemStyle" TargetType="{x:Type ListViewItem}">
            <Setter Property="IsSelected" Value="{Binding FileIsSelected}"/>
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListViewItem">
                        <Grid Height="40">
                            <GridViewRowPresenter/>
                            <Line X1="0.0" Y1="0.0" X2="{Binding ActualWidth, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListView}}}" Y2="0.0" StrokeThickness="1" StrokeDashArray="2" Stroke="Gray" />
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Background" Value="Green"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

In my template, I actually added a line as a separator between 2 rows of ListViewItem.

I just don't get it why the trigger is not working!

Any help will be much appreciate!

A: 

The Background property of a Control is only used in the ControlTemplate. You have replaced the template with one that does not use Background, so setting the property has no effect. You can use {TemplateBinding Background} to bind properties to the Background of the Control. Perhaps you want to bind the Background of the Grid to it:

<ControlTemplate TargetType="ListViewItem">
    <Grid Height="40" Background="{TemplateBinding Background}">
        <GridViewRowPresenter/>
Quartermeister
It' working!!! Thanks!!! 1 line of code solved my 12 hours miserable!
VHanded