开发者

listbox design issue

开发者 https://www.devze.com 2023-04-05 03:07 出处:网络
i am trying to design some nice listbox, but every time i click on the item in the listbox a selection background is ruin开发者_运维百科ed everything...

i am trying to design some nice listbox, but every time i click on the item in the listbox a selection background is ruin开发者_运维百科ed everything... how can i make it irrelevant ?

this is the XAML:

<!-- Site List View -->
<ListBox Grid.Row="1" Name="SiteListBox" ItemsSource="{Binding}" HorizontalContentAlignment="Stretch">
    <ListBox.Background>
        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="White" Offset="0" />
            <GradientStop Color="Gainsboro" Offset="0.805" />
        </LinearGradientBrush>
    </ListBox.Background>
    <ListBox.ItemContainerStyle>
        <Style>
            <Setter Property="Control.Padding" Value="0"></Setter>
            <Style.Triggers>
                <Trigger Property="ListBoxItem.IsSelected" Value="True">
                    <Setter Property="ListBoxItem.Background" Value="DarkRed" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </ListBox.ItemContainerStyle>
    <ListBox.ItemTemplate>
        <DataTemplate>
                <Border Margin="5" BorderThickness="1" BorderBrush="SteelBlue" CornerRadius="4"
                        Background="{Binding Path=Background, RelativeSource={
                        RelativeSource
                        Mode=FindAncestor,
                        AncestorType={x:Type ListBoxItem}
                        }}">
                    <TextBlock Margin="5" Text="{Binding Path=Name}" />
                </Border>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

a also attached a print screen.

listbox design issue


You can change the default colors for when a ListBoxItem container IsSelected. Set them to Transparent to get the effect that you're after

<ListBox ...>
    <ListBox.Resources>
        <!-- Brush for selected item that doesn't have focus -->
        <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
        <!-- Brush for selected item that has focus -->
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
    </ListBox.Resources>
    <!-- ... -->
</ListBox>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号