Exemplo n.º 1
0
        public MessageBoxView()
        {
            InitializeComponent();

            MessageBoxViewModel vm = (MessageBoxViewModel)DataContext;

            vm.PropertyChanged += (_, args) => {
                if (args.PropertyName == nameof(vm.Message))
                {
                    InlineExpression.SetInlineExpression(MessageBlock, vm.Message);
                }
            };

            Loaded += (_, _) => {
                // Window Setup
                _window = Window.GetWindow(this);
                Debug.Assert(_window != null, nameof(_window) + " != null");

                _window.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));

                (double dpiWidthFactor, double dpiHeightFactor) = WindowHelpers.GetDpiFactors(_window);
                Rect screen = vm.openOnScreen?.WorkingArea ?? _window.CurrentScreen().WorkingArea;
                _window.CenterOnScreen(screen, dpiWidthFactor, dpiHeightFactor);


                //Set the window style to noactivate.
                if (!vm.getsFocus)
                {
                    var helper = new WindowInteropHelper(_window);
                    SetWindowLong(helper.Handle, GWL_EXSTYLE, GetWindowLong(helper.Handle, GWL_EXSTYLE) | WS_EX_NOACTIVATE);
                }
            };

            MouseDown += (_, e) => {
                if (e.ChangedButton == MouseButton.Left)
                {
                    _window.DragMove();
                }
            };
        }