2

背景を透明に設定しようとしていますが、下のスクリーンショットでわかるように、マウスを上に置くとListBoxItem、アイテムの上に青い四角形が表示されます。

ListViewItem スクリーン ショット

私はMVVMを使用しており、実装は次のとおりです。

<UserControl.Resources>
    <Style x:Key="HyperLinkStyle" TargetType="{x:Type Hyperlink}">
        <Setter Property="Foreground" Value="#FF0066CC"/>
        <Setter Property="TextDecorations" Value="None" />
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Foreground" Value="#FF0066CC"/>
                <Setter Property="TextDecorations" Value="Underline" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="True">
                <Setter Property="Cursor" Value="Hand"/>
            </Trigger>
        </Style.Triggers>
    </Style>
</UserControl.Resources>

<Grid>
    <Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="0, 10, 0, 0">
        <ListBox x:Name="TeamListView" ItemsSource="{Binding Teams}" BorderThickness="0" 
                 SelectionMode="Single" Background="Transparent">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <DataTemplate.Resources>
                        <Style TargetType="ListBoxItem">
                            <Setter Property="Background" Value="Transparent"/>
                            <Style.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Background" Value="Transparent"/>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </DataTemplate.Resources>
                    <TextBlock Margin="0, 0, 0, 5">
                            <Hyperlink Style="{Binding Source={StaticResource HyperLinkStyle}}" 
                                       Command="{Binding ElementName=TeamListView, Path=DataContext.ConnectToTeam}" 
                                       CommandParameter="{Binding}">
                                <TextBlock Text="{Binding Path=DisplayName}" />
                            </Hyperlink>
                    </TextBlock>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</Grid>

ノート:

  1. hyperlinkstyle は、リストボックス内のハイパーリンク コントロールにハイパーリンクの雰囲気を与えるために使用されます。

  2. リストボックス 'TeamListView' は ItemTemplate DataTemplate を使用します。ItemTemplate のスタイルは ListBoxItem です。背景を透明な onMouseHover に設定することで、ホバー時に色のない青を削除することを意図しています。

私は何が欠けていますか?

4

2 に答える 2

1

これを追加してトリガーListBox.Resourcesを削除してみてください:IsMouseOver

<ListBox.Resources>
    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
</ListBox.Resources>

システムには、システムのテーマに応じてデフォルトのハイライト ブラシがあります。この値を変更するには、 に回す必要がありSystemColorsます。

からの引用MSDN

SystemColors クラスは、ControlBrush、ControlBrushKey、DesktopBrush などのシステム ブラシと色へのアクセスを提供します。システム ブラシは、指定されたシステム カラーで領域をペイントする SolidColorBrush オブジェクトです。システム ブラシは常にベタ塗りを生成します。グラデーションの作成には使用できません。

システム ブラシは、静的リソースまたは動的リソースとして使用できます。アプリケーションの実行中にユーザーがシステム ブラシを変更した場合にブラシを自動的に更新する場合は、動的リソースを使用します。それ以外の場合は、静的リソースを使用してください。

システムでは.NET 4.5を使用しないSystemColorsため、次のことを行う必要があります。

于 2013-09-22T15:44:47.013 に答える