2013-03-26 33 views
8

インターネット上で多くのソリューションを見つけて試しましたが、ホバー効果のWPFリストボックスを無効にすることができますが、どれも私にとってはうまくいかないようです。このスクリーンショットは、私が非表示にしたいかを取り除くのホバー効果を示していますWPFリストボックスのホバー効果を無効にする

hover effect

これは、(簡易版)である私は、現在持っているXAMLコードの:

<ListBox ItemsSource="{Binding Logs}" Grid.Column="1" Width="800" Height="100" > 
    <ListBox.ItemContainerStyle> 
     <Style TargetType="ListBoxItem"> 
      <Style.Triggers> 
       <Trigger Property="Control.IsMouseOver" Value="True"> 
        <Setter Property="Control.Background" Value="Transparent" /> 
       </Trigger> 
      </Style.Triggers> 
     </Style> 
    </ListBox.ItemContainerStyle> 
</ListBox> 

しかし、それは理由や理由のために私のために働くようには思われません。私の親ListBox(バックグラウンドのもの)または別のコントロールはチャンスでチャイルドスタイルをオーバーライドできますか? (私はすでに両親のスタイルをオーバーライドしようとしました)

助けを得ることができます。 :(

+3

トリガーを追加ListBoxItemのデフォルトのスタイルを変更し、私は持っていません。ホバー効果はデフォルトで有効になっています – Tomtom

+0

かなり混乱しています。Windows 8(スクリーンショットに見られるように)とホバー効果が醜い青色で表示されるWindows 7でテストしました。 wpf-applicationは、リストボックスを1分で作成し、違いがあるかどうかを確認します。 – beta

+0

はい、あなたが正しいです、ListBoxはデフォルトでホバー効果を持っていません。私たちはすべてのサブコントロール用にグローバルスタイルを設定しているので、そこにあると思います。このスタイルをオーバーライドする方法はありますか?私は現在、 beta

答えて

13

<Style TargetType="{x:Type ListBoxItem}"> 
     <Setter Property="Background" Value="Transparent"/> 
     <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> 
     <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> 
     <Setter Property="Padding" Value="2,0,0,0"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type ListBoxItem}"> 
        <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true"> 
         <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> 
        </Border> 
        <ControlTemplate.Triggers> 
         <Trigger Property="IsSelected" Value="true"> 
          <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/> 
          <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/> 
         </Trigger> 
         <MultiTrigger> 
          <MultiTrigger.Conditions> 
           <Condition Property="IsSelected" Value="true"/> 
           <Condition Property="Selector.IsSelectionActive" Value="false"/> 
          </MultiTrigger.Conditions> 
          <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}"/> 
          <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}}"/> 
         </MultiTrigger> 
         <Trigger Property="IsEnabled" Value="false"> 
          <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> 
         </Trigger> 
        </ControlTemplate.Triggers> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

はちょうど私がちょうどちょうどリストボックスで新しいWPFアプリケーションを作成

<Trigger Property="IsMouseOver" Value="True"> 
          <Setter Property="Background" Value="Transparent"/> 
         </Trigger> 
+5

なぜ '