【问题标题】:Focus on Excel VSTO WPF application专注于 Excel VSTO WPF 应用
【发布时间】:2014-01-08 18:21:10
【问题描述】:

我在 Excel VSTO 加载项中托管 WPF 应用程序,它在加载时工作正常,但是在最小化 WPF 对话框后,似乎无法使用代码再次激活(聚焦)它。 试过了:

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

但它们都不起作用。

【问题讨论】:

    标签: .net wpf excel vsto


    【解决方案1】:

    好的,我找到了某种解决方案: 在关闭时,我使用事件处理程序将其可见性设置为隐藏:

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

    为了处理最小化 WPF 应用程序的焦点,我将窗口状态设置为 Normal:

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

    这似乎工作正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多