Focus on Excel VSTO WPF application

时光毁灭记忆、已成空白 提交于 2019-12-11 16:47:10

问题


I'm hosting WPF application within an Excel VSTO Add-in and it works fine onload, however after minimizing the WPF dialog, can't seem to get it to activate (focus) again using code. Have tried:

    this.Show();
    this.Activate();
    this.BringIntoView();
    this.Focus();

But none of them work.


回答1:


Ok, I found a solution of somesort: On Close, I used an event handler to set it the visiblity to Hidden:

private void ClientOnClosing(object sender, CancelEventArgs cancelEventArgs)
        {
            cancelEventArgs.Cancel = true;
            _client.Visibility = Visibility.Hidden;
        }

To handle focus a minimized WPF application, I set the windowstate to Normal:

public void ShowDialog()
        {
            if (this.WindowState == WindowState.Minimized)
                this.WindowState = WindowState.Normal;
            this.Show();
        } 

This seems to work ok.



来源:https://stackoverflow.com/questions/21003559/focus-on-excel-vsto-wpf-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!