c# - 如何从任务栏(WPF)隐藏打开的子窗口?

标签 c# .net wpf

当我显示和隐藏子窗口时,即使隐藏子窗口隐藏的窗口仍然出现在任务栏 WPF 中,如何从任务栏隐藏打开的子窗口?

提前致谢, 这是我如何显示对话框的示例:

AlignLocalAxisView alignLocalAxisView = Container.Resolve<AlignLocalAxisView>
    (new ParameterOverride("model", AttributesSelectedItems));
OpenedWindowView = alignLocalAxisView;
alignLocalAxisView.Show();

最佳答案

窗口应该有一个 ShowInTaskbar 属性。

如果您的窗口是在 XAML 中定义的,您可以故意设置该属性,如下所示:

<Window
    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" 
    mc:Ignorable="d"
    x:Class="MyApplication.MainWindow"
    Title="MainWindow" 
    Height="350" Width="425" 
    ShowInTaskbar="False">

您也可以在后面的代码中进行设置:

    this.ShowInTaskbar = false;

这也适用于按名称调用时在代码隐藏中创建的窗口。

    Window myNewWindow = new Window();

    //Set the property to keep the window hidden in the task bar
    myNewWindow.ShowInTaskbar = false;

    //Then, show the window
    myNewWindow.Show();

编辑:根据您的示例代码,以下内容应该有效

    AlignLocalAxisView alignLocalAxisView = Container.Resolve<AlignLocalAxisView>(new ParameterOverride("model", AttributesSelectedItems));

    OpenedWindowView = alignLocalAxisView;

    //Assuming your view extends the Window class, the following will work
    alignLocalAxisView.ShowInTaskbar = false;

    alignLocalAxisView.Show();

希望这足以解决问题。

虽然为了将来引用,这是一个在谷歌上查找的相当快速的解决方案 - 通常值得先搜索答案,因为它有时可以更快地解决问题。

在这种情况下,我将您的问题改写为“在 wpf 中隐藏窗口的任务栏图标”。搜索中并不真正需要子窗口部分,因为 WPF 中的所有窗口基本相同。

希望对您有所帮助。

关于c# - 如何从任务栏(WPF)隐藏打开的子窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51596012/

相关文章:

c# - 根据地区验证日期

c# - 在不同 channel 播放多个音频文件

wpf - xaml 中的常量

c# - 构建您自己的 Web 控件

c# - UWP ListView 数据模板绑定(bind)

c# - 如何从 EventInfo 中获取委托(delegate)对象?

c# - .NET 序列化 XmlNode 问题

c# - 网格控件 WPF 的动态列

c# - 具有 WPF KeyDown 事件的多个键

c# - 寻找关于 : accessing data and populating List/arraylist/list 的建议