码迷,mamicode.com
首页 > Windows程序 > 详细

WPF listBox选中项改变样式

时间:2020-05-23 11:19:24      阅读:84      评论:0      收藏:0      [点我收藏+]

标签:center   color   sof   rop   ade   enter   sele   loaded   xaml   

<UserControl x:Class="Mjj.MyUserControls.LeftMenu"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300" Loaded="UserControl_Loaded">
    <UserControl.Resources>

        <Style x:Key="LeftMenuListBoxStyle" TargetType="ListBox">
            <Setter Property="ItemContainerStyle">
                <Setter.Value>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                    <Border x:Name="Border" Height="46px" BorderThickness="0 0 0 1" BorderBrush="#E4E7ED"  VerticalAlignment="Center">
                                        <Label x:Name="Label" VerticalAlignment="Center" HorizontalAlignment="Center"  FontSize="14px" Foreground="#202122" >
                                            <ContentPresenter></ContentPresenter>
                                        </Label>
                                    </Border>
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsSelected" Value="True">
                                            <Setter TargetName="Border" Property="BorderBrush" Value="#0089FF"></Setter>
                                            <Setter TargetName="Border" Property="Background" Value="#D9E0EE"></Setter>
                                            <Setter TargetName="Label" Property="Foreground" Value="#F2901C" ></Setter>
                                            <Setter TargetName="Border" Property="BorderThickness" Value="0 0 1 0"></Setter>
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>

                       
                    </Style>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <ListBox Style="{StaticResource LeftMenuListBoxStyle}" DisplayMemberPath="MenuName"  BorderThickness="0" Width="160px" Name="ListBoxLeftMenu"  >

    </ListBox>
</UserControl>

 

WPF listBox选中项改变样式

标签:center   color   sof   rop   ade   enter   sele   loaded   xaml   

原文地址:https://www.cnblogs.com/tangchun/p/12941436.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!