C# 在平板电脑模式下在最顶端启动另一个应用程序
当我从应用程序运行另一个.exe时,它会在后台启动,不会在屏幕顶部显示应用程序,而是显示平板电脑模式主屏幕,在正常桌面模式下工作正常,但当我在Windows 10平板电脑模式下运行时,它不会在顶部显示,而是在后台启动 我使用了C# 在平板电脑模式下在最顶端启动另一个应用程序,c#,wpf,windows-10,desktop-application,tablet-pc,C#,Wpf,Windows 10,Desktop Application,Tablet Pc,当我从应用程序运行另一个.exe时,它会在后台启动,不会在屏幕顶部显示应用程序,而是显示平板电脑模式主屏幕,在正常桌面模式下工作正常,但当我在Windows 10平板电脑模式下运行时,它不会在顶部显示,而是在后台启动 我使用了myWindow.TopMost=true,但在Windows 10平板电脑模式下无法正常工作 用于启动exe文件的代码 Process p = new Process(); p.StartInfo.RedirectStandardOutput= true; p.Redir
myWindow.TopMost=true代码>,但在Windows 10平板电脑模式下无法正常工作
用于启动exe文件的代码
Process p = new Process();
p.StartInfo.RedirectStandardOutput= true;
p.RedirectStandardInput = true;
p = Process.Start("myApp.exe");
p.WaitForExit();
我正在调用(启动)的exe是我自己的exe应用程序(不是系统应用程序),我正在windows 10上运行应用程序
它只是在平板电脑模式下无法在顶部工作(我的应用程序只针对平板电脑)
感谢您的帮助 由于我遇到了类似的情况,(它与平板电脑或windows-10无关。只有WPF和最上面的标签有相似之处),我将向您展示我如何解决它:
我希望FilterWindow始终位于最顶端(但仅适用于我的应用程序,而不适用于我操作系统中的整个应用程序集)
查看我的代码。愿它对你有帮助
private void OnFilter() {
var filterViewModel = ViewModelLocator.FilterViewModel;
/* ... */
var filterWindow = new FilterWindow {
DataContext = filterViewModel,
Owner = GetParentWindow()
};
filterWindow.ShowDialog();
SelectedIndex = 0;
}
private static Window GetParentWindow() {
Window parent = null;
var activeWindows = Application.Current.Windows.Cast<Window>().Where(item => (item).IsActive).ToList();
if (activeWindows.Any()) {
parent = activeWindows[activeWindows.Count - 1];
}
else {
foreach (var item in
Application.Current.Windows.Cast<object>().Where(item => item.GetType().Name == typeof(RibbonWindow).Name)) {
parent = item as Window;
}
}
return parent;
}
private void OnFilter(){
var filterViewModel=ViewModelLocator.filterViewModel;
/* ... */
var filterWindow=新的filterWindow{
DataContext=filterViewModel,
所有者=GetParentWindow()
};
filterWindow.ShowDialog();
SelectedIndex=0;
}
私有静态窗口GetParentWindow(){
窗口父项=null;
var activeWindows=Application.Current.Windows.Cast().Where(item=>(item.IsActive).ToList();
if(activeWindows.Any()){
父项=activeWindows[activeWindows.Count-1];
}
否则{
foreach(中的var项)
Application.Current.Windows.Cast().Where(item=>item.GetType().Name==typeof(RibbonWindow.Name)){
父项=项目作为窗口;
}
}
返回父母;
}
神奇之处在于Owner=GetParentWindow()
如果不设置所有者
,过滤器窗口
的行为很可笑
希望对你有帮助。如果否,我将删除响应。(这不适合评论)Moerfi使用Owner=GetParentWindow()
的解决方案非常有效,非常感谢这个解决方案。它还解决了我遇到的另一个问题
我正在为Surface 3编写一个应用程序,它在平板电脑模式下运行在Windows 10 Pro上,每当关闭消息框
或自定义对话框控制框时,与返回父窗口相反,Win 10将进入开始菜单
就好像一旦对话框控件打开,父窗口就被置于后台,因此当对话框控件关闭时,Win 10没有活动窗口可切换回后台
在子对话框控件上设置所有者解决了该问题。非常感谢。您应该设置隐藏应用程序的父窗口。如果没有设置,则TopMost=true
将无法帮助您。感谢您的回复,但是我应该在哪里编写此代码,因为我正在启动新的exe(应用程序)。当我发布代码从Process.Start()调用exe时…?@RahulShirphule,对于进程,您应该从WinApi处理窗口函数SetParent
应执行此操作(启动EXE时)请参阅更多:。另外,这对你来说也很有意思:是的,我浏览了这个链接。但是什么时候调用setParent方法没有提到,是指在p=Process.Start(“myApp.exe”)之前还是之后;p、 WaitForExit();我两个都试过了,但都不走运……你知道吗。。?请让我知道?@RahulShirphule,我在这里看到(附加的url),在进程启动后调用SetParent。此外,这里: