当我显示和隐藏子窗口时,即使隐藏子窗口隐藏的窗口仍然出现在任务栏 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/