问题
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