基于ListBox制作一个好看的侧边菜单导航栏

1.代码实现

MainWindow.xaml 代码如下:

csharp 复制代码
<Window x:Class="UIDamo_WPF.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:UIDamo_WPF"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800" Background="#2b2b2b">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="130"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Rectangle Fill="#111111"/>
            <ListBox Margin="0 5 0 0" Background="Transparent" Foreground="White" BorderThickness="0" FontSize="16" Name="listMenu">
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="ListBoxItem">
                                    <StackPanel Height="35" Orientation="Horizontal" Background="Transparent" Name="container" Cursor="Hand">
                                        <Rectangle Fill="Green" VerticalAlignment="Stretch" Width="5" Visibility="Hidden" Name="leftSlideRectangle"/>
                                        <ContentPresenter  VerticalAlignment="Center" Margin="15 0 0 0"/>
                                    </StackPanel>
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsSelected" Value="True">
                                            <Setter Property="Visibility" Value="Visible" TargetName="leftSlideRectangle"/>
                                            <Setter Property="Background" Value="#3a3a3a" TargetName="container"/>
                                        </Trigger>
                                        <Trigger Property="IsMouseOver" Value="True">
                                            <Setter Property="Visibility" Value="Visible" TargetName="leftSlideRectangle"/>
                                            <Setter Property="Opacity" Value="0.5" TargetName="leftSlideRectangle"/>
                                            <Setter Property="Background" Value="#1a1a1a" TargetName="container"/>
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </ListBox.ItemContainerStyle>
                <ListBoxItem  Content="首页"/>
                <ListBoxItem  Content="用户管理"/>
                <ListBoxItem  Content="权限设置"/>
                <ListBoxItem  Content="菜单管理"/>
                <ListBoxItem  Content="配置管理"/>
                <ListBoxItem  Content="设备管理"/>
                <ListBoxItem  Content="数据管理"/>
                <ListBoxItem  Content="系统配置"/>
                <ListBoxItem  Content="基础配置"/>
                <ListBoxItem  Content="退出系统"/>
            </ListBox>
        </Grid>
</Window>

相关推荐
Java林间4 小时前
Zookeeper是什么?基于zookeeper实现分布式锁
分布式·zookeeper·wpf
zizisuo8 小时前
1.微服务拆分与通信模式
微服务·wpf
程序员秘密基地12 小时前
基于c#,wpf,ef框架,sql server数据库,音乐播放器
sql·sqlserver·c#·.net·wpf
Zhen (Evan) Wang12 小时前
.NET 6 WPF 利用CefSharp.Wpf.NETCore显示PDF文件
.net·wpf·.netcore
冰茶_1 天前
WPF特性分析
学习·microsoft·c#·wpf
qq_196055872 天前
最快打包WPF 应用程序
wpf
baivfhpwxf20233 天前
wpf ScaleTransform
wpf
C#_西哥3 天前
wpf stylet框架 关于View与viewmodel自动关联绑定的问题
wpf
wqq10273 天前
WPF 图标原地旋转
wpf
续亮~3 天前
基于Redis实现RAG架构的技术解析与实践指南
java·redis·架构·wpf·springai·文档检索