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

相关推荐
code bean1 天前
【WPF】WPF 项目实战:构建一个可增删、排序的光源类型管理界面(含源码)
wpf
沉到海底去吧Go1 天前
【图片识别改名】如何批量将图片按图片上文字重命名?自动批量识别图片文字并命名,基于图片文字内容改名,WPF和京东ocr识别的解决方案
ocr·wpf·图片识别改名·图片识别重命名·图片内容改名
lph19721 天前
自定义事件wpf
wpf
code bean1 天前
【WPF】从普通 ItemsControl 到支持筛选的 ItemsControl:深入掌握 CollectionViewSource 用法
wpf
碎碎念的安静2 天前
WPF可拖拽ListView
c#·wpf
界面开发小八哥2 天前
界面组件DevExpress WPF中文教程:Grid - 如何识别行和卡片?
.net·wpf·界面控件·devexpress·ui开发
TwilightLemon4 天前
WPF 使用CompositionTarget.Rendering实现平滑流畅滚动的ScrollViewer,支持滚轮、触控板、触摸屏和笔
wpf
Vae_Mars5 天前
WPF中自定义消息弹窗
wpf
Magnum Lehar5 天前
GameEngine游戏引擎前端界面wpf页面实现
前端·游戏引擎·wpf
TA远方6 天前
【C#】一个简单的http服务器项目开发过程详解
服务器·http·c#·wpf·web·winform·console