在 WPF 中创建侧边栏 - 类似于 Windows 桌面应用程序的弹出窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11826568/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Creating a sidebar - flyout like Windows desktop app in WPF
提问by Dannyboy
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).
我想要做的是在 WPF 中创建一个桌面应用程序,它的 UI 是这样一个小图标将固定在屏幕左边缘的中心,点击(或悬停)将滑动打开侧边栏(如谷歌桌面栏)沿屏幕左边缘运行(固定位置,不能移动)。
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 ??
请注意,我要求的可能类似于应用栏,但我不希望像应用栏那样移动左边缘的桌面图标,即我不希望它占用桌面空间... .有人可以给我建议出路吗??
I have implemented a partial solution using this, but i cant get the slide animation and fixed position to workout
我已经使用这个实现了部分解决方案,但我无法获得幻灯片动画和固定位置来锻炼
回答by Bas
Something like this could work:
这样的事情可以工作:
then of course you could create a slide in animation for the sidebar. This shows (partial) transparency and the switching principle.
那么当然你可以为侧边栏创建一个动画幻灯片。这显示了(部分)透明度和切换原理。
XAML:
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">></Button>
</Grid>
</Window>
C#:
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 = ">";
}
}
回答by bto.rdz
Based on this answer and more answers on this site I made a side bar, I liked the result so i made a repo.
基于这个答案和这个网站上的更多答案,我做了一个侧边栏,我喜欢这个结果,所以我做了一个回购。
https://github.com/beto-rodriguez/MaterialMenu
https://github.com/beto-rodriguez/MaterialMenu
you can install it from nuget too.
您也可以从 nuget 安装它。
here is an example
这是一个例子
<materialMenu:SideMenu HorizontalAlignment="Left" x:Name="Menu"
MenuWidth="300"
Theme="Default"
State="Hidden">
<materialMenu:SideMenu.Menu>
<ScrollViewer VerticalScrollBarVisibility="Hidden">
<StackPanel Orientation="Vertical">
<Border Background="#337AB5">
<Grid Margin="10">
<TextBox Height="150" BorderThickness="0" Background="Transparent"
VerticalContentAlignment="Bottom" FontFamily="Calibri" FontSize="18"
Foreground="WhiteSmoke" FontWeight="Bold">Welcome</TextBox>
</Grid>
</Border>
<materialMenu:MenuButton Text="Administration"></materialMenu:MenuButton>
<materialMenu:MenuButton Text="Packing"></materialMenu:MenuButton>
<materialMenu:MenuButton Text="Logistics"></materialMenu:MenuButton>
</StackPanel>
</ScrollViewer>
</materialMenu:SideMenu.Menu>
</materialMenu:SideMenu>