C# WPF 实现侧边栏自动隐藏

By jerryxjr1220 at 2023-10-07 • 0人收藏 • 400人看过

用HandyControl的Drawer实现

screenshots.gif

<hc:GlowWindow x:Class="WPFHandyControlDemo.Views.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:model="clr-namespace:WPFHandyControlDemo.Models"
               xmlns:vm="clr-namespace:WPFHandyControlDemo.ViewModels"
               xmlns:view="clr-namespace:WPFHandyControlDemo.Views"
               xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
               xmlns:local="clr-namespace:WPFHandyControlDemo"
               xmlns:hc="https://handyorg.github.io/handycontrol"
               d:DataContext="{d:DesignInstance Type=vm:MainViewModel}"
               mc:Ignorable="d"
               Title="Drawer Demo" Width="800" Height="450">
    <hc:SimplePanel>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="30"/>
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <RadioButton Margin="10" HorizontalAlignment="Stretch" Grid.Column="0" Content=" "
                          IsChecked="{Binding IsOpen,ElementName=DrawerLeft}" Style="{StaticResource RadioButtonSameAsButtonWarning}"/>
            <Grid Grid.Column="1">
                <Border BorderThickness="1" BorderBrush="DarkGray">
                    <TextBlock Text="Main Content" HorizontalAlignment="Center" VerticalAlignment="Center"></TextBlock>
                </Border>
                
            </Grid>
        </Grid>
        <hc:Drawer x:Name="DrawerLeft" Dock="Left" ShowMode="Push">
            <Border Background="{DynamicResource RegionBrush}" Width="200" BorderThickness="0,1,0,0"
                    BorderBrush="{DynamicResource BorderBrush}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <TextBlock Margin="10,0,0,0" Text="Drawer SideBar" Style="{StaticResource TextBlockTitle}"
                               HorizontalAlignment="Left" />
                    <Button Grid.Row="0" HorizontalAlignment="Right" Click="ButtonBase_OnClick"
                            Foreground="{DynamicResource PrimaryTextBrush}" Style="{StaticResource ButtonIcon}"
                            hc:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}" />
                    <ListBox Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Top" Width="200">
                        <ListBoxItem>Item 1</ListBoxItem>
                        <ListBoxItem>Item 2</ListBoxItem>
                    </ListBox>
                </Grid>
            </Border>
        </hc:Drawer>
       
    </hc:SimplePanel>

</hc:GlowWindow>
//侧边栏关闭按钮的点击事件
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
    DrawerLeft.IsOpen = false;
}


1 个回复 | 最后更新于 2023-10-07
2023-10-07   #1

老哥你对编程热情很高啊,我假期电脑都没开过

登录后方可回帖

登 录
信息栏
 私人小站

本站域名

ChengXu.XYZ

投诉联系:  popdes@126.com



快速上位机开发学习,本站主要记录了学习过程中遇到的问题和解决办法及上位机代码分享

这里主要专注于学习交流和经验分享.
纯私人站,当笔记本用的,学到哪写到哪.
如果侵权,联系 Popdes@126.com

友情链接
Aardio官方
Aardio资源网


才仁机械


网站地图SiteMap

Loading...