WPF制作好看的侧边栏控件

WPF制作好看的侧边栏控件

界面代码如下:

<Window x:Class="侧边停靠按钮.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:侧边停靠按钮"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid  Background="#3b3b3b" >
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="150"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Rectangle Fill="#111111"/>
        <ListBox Name="lsb" Foreground="White" Margin="0 50 0 0" Background="Transparent" BorderThickness="0" FontSize="16">
            <ListBox.ItemContainerStyle>
                <Style TargetType="ListBoxItem">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="ListBoxItem">
                                <StackPanel x:Name="Container"  Height="35" Orientation="Horizontal" VerticalAlignment="Center" Background="Transparent"  Cursor="Hand" >
                                    <Rectangle Fill="DarkRed" VerticalAlignment="Stretch" Width="5" Visibility="Hidden" Name="Rectagle"/>
                                    <ContentPresenter VerticalAlignment="Center" Margin="15 0 0 0"/>
                                </StackPanel>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsSelected" Value="true">
                                        <Setter Property="Visibility" Value="Visible" TargetName="Rectagle"/>
                                        <Setter Property="Background" Value="#3a3a3a" TargetName="Container"/>
                                    </Trigger>

                                    <Trigger Property="IsMouseOver" Value="true">
                                        <Setter Property="Visibility" Value="Visible" TargetName="Rectagle"/>
                                        <Setter Property="Background" Value="#1a1a1a" TargetName="Container"/>
                                    </Trigger>

                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </ListBox.ItemContainerStyle>
            <ListBoxItem>Weapon</ListBoxItem>
            <ListBoxItem>Talk</ListBoxItem>
            <ListBoxItem>Sell</ListBoxItem>
            <ListBoxItem>Status</ListBoxItem>
            <ListBoxItem>Spell</ListBoxItem>
        </ListBox>
    </Grid>
</Window>


效果如下:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值