aboutsummaryrefslogtreecommitdiff
path: root/src/test/burn/WixToolset.WixBA/RootView.xaml.cs
blob: e1ee19db412b77206c0a77f8258eecae9ce87c33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.

namespace WixToolset.WixBA
{
    using System.ComponentModel;
    using System.Windows;
    using System.Windows.Interop;

    /// <summary>
    /// Interaction logic for View.xaml
    /// </summary>
    public partial class RootView : Window
    {
        /// <summary>
        /// Creates the view populated with it's model.
        /// </summary>
        /// <param name="viewModel">Model for the view.</param>
        public RootView(RootViewModel viewModel)
        {
            this.DataContext = viewModel;

            this.Loaded += (sender, e) => WixBA.Model.Engine.CloseSplashScreen();
            this.Closed += (sender, e) => this.Dispatcher.InvokeShutdown(); // shutdown dispatcher when the window is closed.

            this.InitializeComponent();

            viewModel.Dispatcher = this.Dispatcher;
            viewModel.ViewWindowHandle = new WindowInteropHelper(this).EnsureHandle();
        }

        /// <summary>
        /// Event is fired when the window is closing.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Closing(object sender, CancelEventArgs e)
        {
            RootViewModel rvm = this.DataContext as RootViewModel;
            if ((null != rvm) && (InstallationState.Applying == rvm.InstallState))
            {
                rvm.CancelButton_Click();
                if (rvm.Canceled)
                {
                    // Defer closing until the engine has canceled processing.
                    e.Cancel = true;
                    rvm.AutoClose = true;
                }
            }
        }
    }
}