Rubans
Rubans

Reputation: 4488

Focus on Excel VSTO WPF application

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.

Upvotes: 0

Views: 427

Answers (1)

Rubans
Rubans

Reputation: 4488

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.

Upvotes: 2

Related Questions