2011-08-10 57 views
2

我有一個簡單的WPF ListView,其中定義了兩列。默認情況下,當您將鼠標移動到某一行的任何部分時,它會在跟蹤外觀中顯示該行(我正在使用帶Aero的Windows 7)。這裏是的XAML如預期顯示該工作一個簡單的例子...WPF ListViewItem.IsMouseOver對整行不返回True

<Page 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:sys="clr-namespace:System;assembly=mscorlib"> 
    <Grid> 
     <ListView> 
     <ListView.View> 
      <GridView> 
      <GridViewColumn Header="First" Width="200"/> 
      <GridViewColumn Header="Second" Width="200"/> 
      </GridView> 
     </ListView.View> 
     <sys:DateTime>1/2/3</sys:DateTime> 
     <sys:DateTime>4/5/6</sys:DateTime> 
     <sys:DateTime>7/8/9</sys:DateTime> 
     <sys:DateTime>10/11/12</sys:DateTime> 
     </ListView> 
    </Grid> 
    </Page> 

我想覆蓋ListViewItem風格和跟蹤時自定義行的外觀。下面是示例的XAML我已經加入到上述ListView ...

<ListView.ItemContainerStyle> 
    <Style TargetType="{x:Type ListViewItem}"> 
     <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="ListBoxItem"> 
      <Border x:Name="Bd"> 
       <GridViewRowPresenter /> 
      </Border> 
      <ControlTemplate.Triggers> 
      <Trigger Property="IsMouseOver" Value="True"> 
       <Setter TargetName="Bd" Property="Background" Value="Red"/> 
      </Trigger> 
      </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
     </Setter> 
    </Style> 
    </ListView.ItemContainerStyle> 

只顯示該行的跟蹤,當鼠標直接在裏面兩列的一個文本。如果鼠標位於繪製的文本之間或超出最後一列的右側,則不顯示爲跟蹤。

好像IsMouseOver觸發器只在鼠標下面有實際的內容時才返回True,當我希望它在鼠標位於行的任何部分時返回True時,即使該行的該區域碰巧是空。任何想法如何解決這個問題?

回答

1

將BorderAlignment的邊框設置爲Stretch併爲其指定透明(或默認)背景。這將給鼠標一些東西要突出顯示

+0

添加Background = Transparent很好地解決了問題。謝謝你的訣竅。 –