WPF MetroWindow Listbox удалить Цвет фокуса - PullRequest
0 голосов
/ 10 января 2019

Я долго искал решение, но так как я не нашел ничего полезного, я задаю свой вопрос. Я использую MahApps Metro в WPF, и он поддерживает Tile View. У меня есть несколько рисунков, которые применяются к плитке, и сама плитка хранится в ListBox, так что она выглядит как меню «Пуск» в Windows 10. Но всякий раз, когда я наводю указатель мыши на элемент мозаики, цвет фокуса listBox становится видимым

enter image description here

Поскольку это плитки, а фокус списка мне не нужен, то синее окружение выглядит для меня просто уродливо, но я не нашел способа его отключить. Мой код XAML довольно скромный:

<Controls:MetroWindow x:Class="Berichtsheft_Analyzer.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:Berichtsheft_Analyzer"
    xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
    mc:Ignorable="d"
    Title="Report Portfolio Analyzer" 
    Height="700"
    Width="900"
    Icon="C:\Users\lerchers\Desktop\testbilder BCS\moustache.png">

<Grid Name="Grid1">
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition  Height="188"/>
    </Grid.RowDefinitions>
    <ListBox Name="Hans" ScrollViewer.HorizontalScrollBarVisibility="Disabled" >
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel />
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Margin="15,10">

                    <Controls:Tile Title="{Binding Path=_Name}" Background="Brown" TiltFactor="0" Width="225" Height="225">
                        <Rectangle Width="160" Height="160" >
                            <Rectangle.Fill>
                                <ImageBrush ImageSource="{Binding Path=_Imagesrc}"/>
                            </Rectangle.Fill>
                        </Rectangle>
                    </Controls:Tile>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</Grid>

Что мне нужно сделать, чтобы цвет фокуса был как минимум на «Белый», чтобы он больше не отображался

1 Ответ

0 голосов
/ 10 января 2019

Вам нужно получить копию ItemContainerStyle стандартного ListView с помощью выражения blend и удалить триггеры, которые устанавливают границу контейнера.

<Style x:Key="ListBoxItemStyle1" TargetType="{x:Type ListBoxItem}">
    <Setter Property="SnapsToDevicePixels" Value="True"/>
    <Setter Property="Padding" Value="4,1"/>
    <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="Background" Value="Transparent"/>
    <Setter Property="BorderBrush" Value="Transparent"/>
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
    <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>
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="IsMouseOver" Value="True"/>
                        </MultiTrigger.Conditions>
                        <Setter Property="Background" TargetName="Bd" Value="{StaticResource Item.MouseOver.Background}"/>
                        <!-- change this one to white? -->
                        <Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource Item.MouseOver.Border}"/>
                    </MultiTrigger>
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="Selector.IsSelectionActive" Value="False"/>
                            <Condition Property="IsSelected" Value="True"/>
                        </MultiTrigger.Conditions>
                        <Setter Property="Background" TargetName="Bd" Value="{StaticResource Item.SelectedInactive.Background}"/>
                        <Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource Item.SelectedInactive.Border}"/>
                    </MultiTrigger>
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="Selector.IsSelectionActive" Value="True"/>
                            <Condition Property="IsSelected" Value="True"/>
                        </MultiTrigger.Conditions>
                        <Setter Property="Background" TargetName="Bd" Value="{StaticResource Item.SelectedActive.Background}"/>
                        <!-- change this one to white? -->
                        <Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource Item.SelectedActive.Border}"/>
                    </MultiTrigger>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter Property="TextElement.Foreground" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

и используйте такой стиль:

<ListBox Name="Hans" ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
ItemContainerStyle="{StaticResource ListBoxItemStyle1}">
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...