在 WPF 中创建侧边栏 - 类似于 Windows 桌面应用程序的弹出窗口 [英] Creating a sidebar - flyout like Windows desktop app in WPF

查看:46
本文介绍了在 WPF 中创建侧边栏 - 类似于 Windows 桌面应用程序的弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是在 WPF 中创建一个桌面应用程序,它的 UI 是这样一个小图标将固定在屏幕左边缘的中心,点击(或悬停)将滑动打开侧边栏(像谷歌桌面栏)沿着屏幕左边缘运行(固定位置,不能移动).

what i am trying to do is create a Desktop application in WPF whose UI is such that a small icon will remain fixed in the center of the left edge of screen and on click(or maybe hover) will slide open a sidebar(like the google desktop bar) running along the left edge of the screen (fixed position, cannot be moved).

请注意,我要求的可能类似于应用栏,但我不希望像应用栏那样移动左边缘的桌面图标,即我不希望它占用桌面空间....有人可以给我建议出路吗??

do note that what i'm asking for might be like an appbar but i do not want the desktop icons along the left edge to be moved as it happens with an appbar i.e. i do not want it to hog up the desktop spacce....can anyone please suggest me a way out ??

我已经使用 this 实现了部分解决方案,但我无法获得幻灯片动画和固定位置锻炼

I have implemented a partial solution using this, but i cant get the slide animation and fixed position to workout

推荐答案

这样的事情可以工作:

当然,您可以为侧边栏创建动画幻灯片.这显示了(部分)透明度和切换原理.

then of course you could create a slide in animation for the sidebar. This shows (partial) transparency and the switching principle.

XAML:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        WindowStyle="None" Topmost="True" WindowState="Maximized" 
        AllowsTransparency="True" Background="Transparent">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Rectangle Name="rect" Width="100" VerticalAlignment="Stretch" Fill="#99000000" Visibility="Collapsed" />
        <Button Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Width="32" Height="32" FontSize="16" VerticalAlignment="Center" HorizontalAlignment="Right" Background="White" Click="Button_Click">&gt;</Button>
    </Grid>
</Window>

C#:

private void Button_Click(object sender, RoutedEventArgs e)
{
    if (rect.Visibility == System.Windows.Visibility.Collapsed)
    {
        rect.Visibility = System.Windows.Visibility.Visible;
        (sender as Button).Content = "<";
    }
    else 
    {
        rect.Visibility = System.Windows.Visibility.Collapsed;
        (sender as Button).Content = ">";
    }        
}

这篇关于在 WPF 中创建侧边栏 - 类似于 Windows 桌面应用程序的弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆