简体   繁体   English

在平板电脑模式下最顶层启动另一个应用程序

[英]Start another application on top most in tablet mode

When I run another .exe from my application it starts in the background and does not show the application on top of the screen instead shows tablet mode home screen , it's working fine in normal desktop mode but when I run it in Windows 10 Tablet mode then it does not show on top it starts in the background. 当我从应用程序运行另一个.exe时,它在后台启动,而不在屏幕顶部显示该应用程序,而是在平板电脑模式的主屏幕上显示,它在正常的桌面模式下工作正常,但是当我在Windows 10平板电脑模式下运行时它不显示在顶部,而是从背景开始。

I've used myWindow.TopMost = true; 我用过myWindow.TopMost = true; , but it does not work as intended in Windows 10 Tablet Mode. ,但在Windows 10平板电脑模式下无法正常工作。

Code used to start exe file 用于启动exe文件的代码

Process p = new Process();
p.StartInfo.RedirectStandardOutput= true;
p.RedirectStandardInput = true;
p = Process.Start("myApp.exe");
p.WaitForExit();

the exe I'm invoking(starting) is my own exe application(it's not system app), I'm running app on windows 10. 我正在调用(启动)的exe是我自己的exe应用程序(不是系统应用程序),我正在Windows 10上运行应用程序。

It's only not working on top in Tablet mode( and I'm targeting my application only for Tablets). 它仅在平板电脑模式下无法正常运行(并且我的应用程序仅针对平板电脑)。

Any help is appreciated..! 任何帮助表示赞赏..!

As I faced a similar situation, (it is not tablet, or windows-10 related. Has similarities only by WPF and TopMost tags) I'll show you how I resolve it: I would like to have the FilterWindow always TopMost (but only over my application, not over entire set of apps in my Operating System) 当我遇到类似的情况时(与平板电脑或Windows 10无关。只有WPFTopMost标签具有相似性),我将向您展示如何解决它:我希望FilterWindow始终为TopMost(但仅而不是整个操作系统中的整个应用程序)

See my code. 看我的代码。 May it'll helps you. 希望它能为您提供帮助。

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;
}

The magic is Owner = GetParentWindow() . 神奇的是Owner = GetParentWindow()
Without setting the Owner the FilterWindow had a ridiculous behavior. 没有设置OwnerFilterWindow具有可笑的行为。

Hope it helps you. 希望对您有帮助。 If no, I will remove the response. 如果否,我将删除回复。 (it does not fit in a comment) (它不适合评论)

Moerfi's solution of using Owner = GetParentWindow() worked surperb, much thanks for this solution. Moerfi使用Owner = GetParentWindow()的解决方案非常成功,非常感谢该解决方案。 It also solved another problem I had. 它还解决了我遇到的另一个问题。

I am writing an application for Surface 3 that runs on Windows 10 Pro on tablet mode, whenever a MessageBox or custom dialog control box is closed, as opposed to going back to parent window, Win 10 goes to start menu. 我正在编写适用于Surface 3的应用程序,该应用程序可在平板电脑模式下的Windows 10 Pro上运行,每当关闭MessageBox或自定义对话框控件而不是返回父窗口时,Win 10就会进入开始菜单。

As if once the dialog control is opened the parent window is being placed into background, so when dialog control is closed there is no active window for Win 10 to switch back. 仿佛一旦打开对话框控件,父窗口便被置于背景中,所以当关闭对话框控件时,没有活动窗口可供Win 10切换回。

Setting owner on child dialog control solved that problem. 在子对话框控件上设置所有者可以解决该问题。 Thank you very much. 非常感谢你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM