After activation function WPF minimized window display can not form

After activation function WPF minimized window display can not form

Today test brother gave me some problems, one of the problems is that, click on a link web side, it is able to start the local application, and if the local application is started (inter-tcp-process communication through), then you should to be able to show that local application window. But when he was tested and found not the desired effect.

After several tests, that an invalid situation is minimized when the activated form is displayed in a form not provided, if the form is just behind another window is active.
Test code is as follows:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        this.WindowState = WindowState.Maximized;
        this.SleepShow();
    }
    public void SleepShow(double sleep = 5)
    {
        DispatcherTimer dispatcherTimer = new DispatcherTimer();
        dispatcherTimer.Interval = TimeSpan.FromSeconds(sleep);
        dispatcherTimer.Tick += (sender, e) => {
            this.Activate();
            Console.WriteLine("激活显示窗体");
        };
        dispatcherTimer.Start();
    }
}

In the current form is not minimized state are valid, that is not to minimize the use.
Join Topmost = true; it's useless. The final solution is, you need to first form WindowState revert to the original state, certainly non-Minimized state. Processing code is as follows:

public partial class MainWindow : Window
{
    private WindowState windowState;
    public MainWindow()
    {
        InitializeComponent();
        this.WindowState = WindowState.Maximized;
        this.StateChanged += MainWindow_StateChanged;
        this.SleepShow();
        this.windowState = WindowState.Maximized;
    }

    private void MainWindow_StateChanged(object sender, EventArgs e)
    {
        if(this.WindowState == WindowState.Minimized)
        {
        }
        else
        {
            this.windowState = this.WindowState;//保存非最小化的状态
        }
    }

    public void SleepShow(double sleep = 5)
    {
        DispatcherTimer dispatcherTimer = new DispatcherTimer();
        dispatcherTimer.Interval = TimeSpan.FromSeconds(sleep);
        dispatcherTimer.Tick += (sender, e) => {
            if(this.WindowState == WindowState.Minimized)//判断当前如果是最小化状态,那么就需要还原,再激活
            {
                this.WindowState = this.windowState;//还原状态
            }
            this.Activate();
            Console.WriteLine("激活显示窗体");
        };
        dispatcherTimer.Start();
    }
}

Another problem is that when adjusting the window size, get the value of ActualHeight and ActualWidth the form of TabControl is always the same, in addition to open an application to get the test, the result value is correct, look ignorant force. Finally, look up the node is eventually discovered -V- because Viewbox control caused. ViewBox last adjusted the position of use, problem solving, self-test after a few times, sent packing testing, verification through.

Guess you like

Origin www.cnblogs.com/zzr-stdio/p/11883643.html