基于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>

相关推荐
绿龙术士9 小时前
构建现代化WPF应用:数据驱动开发与高级特性解析
c#·wpf
wangnaisheng2 天前
【WPF】Opacity 属性的使用
wpf
姬激薄2 天前
配置Hadoop集群-集群配置
wpf
python算法(魔法师版)2 天前
.NET 在鸿蒙系统上的适配现状
华为od·华为·华为云·.net·wpf·harmonyos
大道随心3 天前
【wpf】11 在WPF中实现父窗口蒙版效果:原理详解与进阶优化
wpf
zizisuo3 天前
9.1.领域驱动设计
wpf
大道随心3 天前
【wpf】10 C#树形控件高效实现:递归构建与路径查找优化详解
开发语言·c#·wpf
离歌漠3 天前
WPF内嵌其他进程的窗口
c#·wpf
沉到海底去吧Go4 天前
【身份证识别表格】批量识别身份证扫描件或照片保存为Excel表格,怎么大批量将身份证图片转为excel表格?基于WPF和腾讯OCR的识别方案
ocr·wpf·excel·身份证识别表格·批量扫描件身份证转表格·图片识别表格·图片识别excel表格
csdn_aspnet4 天前
WPF 性能 UI 虚拟化 软件开发人员的思考
ui·wpf