wpf 显示/隐藏 Mahapps 弹出控件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30645388/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 13:11:06  来源:igfitidea点击:

Show/hide Mahapps Flyout control

c#.netwpfxamlmahapps.metro

提问by cactodevcie

How can I show/hide MahApps Flyoutcontrol? Now I have:

如何显示/隐藏MahApps Flyout控件?我现在有:

<controls:FlyoutsControl>
    <controls:Flyout Header="Flyout" Position="Right" Width="200" IsOpen="True">
        <TextBlock FontSize="24">Hello World</TextBlock>
    </controls:Flyout>
</controls:FlyoutsControl>

And it's open, but when I click the button with arrow I can't show it again.

它是打开的,但是当我单击带有箭头的按钮时,我无法再次显示它。

回答by Hossein Narimani Rad

You can simply use something like this:

你可以简单地使用这样的东西:

yourMahAppFlyout.IsOpen = true;

Also you can bind the Flyout visibility to a WindowCommand(LeftWindowCommand/RightWindowCommand) so whenever you close the Flyout you can reopen using a ToggleButton(for example) from the top of the window.

您还可以将 Flyout 可见性绑定到WindowCommand( LeftWindowCommand/ RightWindowCommand),因此无论何时关闭 Flyout,您都可以使用ToggleButton(例如)从窗口顶部重新打开。

<Controls:MetroWindow.Flyouts>
    <Controls:FlyoutsControl>
        <Controls:Flyout x:Name="yourMahAppFlyout"/>
    </Controls:FlyoutsControl>
</Controls:MetroWindow.Flyouts>

<Controls:MetroWindow.RightWindowCommands>
    <Controls:WindowCommands>
        <ToggleButton Content="Layers" 
        IsChecked="{Binding ElementName=yourMahAppFlyout, Path=IsOpen}" Cursor="Hand"/>               
    </Controls:WindowCommands>
</Controls:MetroWindow.RightWindowCommands>