【问题标题】:How can hide the opened child windows from taskbar (WPF)?如何从任务栏(WPF)隐藏打开的子窗口?
【发布时间】:2018-07-30 14:15:41
【问题描述】:

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

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

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

【问题讨论】:

    标签: c# .net wpf


    【解决方案1】:

    窗口应该有一个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();
    

    希望这足以解决问题。

    不过,为了将来参考,这是在 google 上查找的一个相当快速的解决方案 - 通常值得先搜索答案,因为它有时可以更快地解决问题。

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

    希望对你有所帮助。

    【讨论】:

    • 谢谢。我已经尝试过这种方法,但它对我不起作用。
    • 你能发布一些示例代码吗?这种方法确实有效,因此您的代码中可能还有其他东西阻止了它。如果没有更多信息,很难提出解决方案。
    • 我正在使用 MVVM 并且我没有使用 ShowDialog 方法,我正在使用 show 方法来显示子窗口。他们是单身人士,所以当我使用也隐藏不关闭方法时。所以窗户被隐藏而不是被折叠。
    • 显示窗口的方式不应该有所不同。如果你有一个子窗口,这个窗口是Window 类的一个实例。您只需要在对象上设置该属性。您可以发布创建子窗口的代码吗?
    • @MohammadAbuSubha 如果您可以编辑您的问题以包含显示您的窗口的代码,那么为您解决这个问题会更容易。
    猜你喜欢
    • 2015-12-18
    • 2017-05-28
    • 1970-01-01
    • 2011-08-03
    • 1970-01-01
    • 1970-01-01
    • 2010-11-18
    • 2013-08-22
    • 2011-03-16
    相关资源
    最近更新 更多