Beispiel #1
0
        public static void Attach(ModalView modalView)
        {
            var window     = ApplicationHelpers.GetMainWindow();
            var firstChild = window.GetLogicalChildren().FirstOrDefault();

            if (firstChild is Grid grid)
            {
                _reserved = false;
                grid.Children.Add(modalView);

                return;
            }

            if (_grid == null)
            {
                _grid = new Grid();
            }

            window.Content = null;

            _reserved = true;
            _grid.Children.Add((IControl)firstChild);
            _grid.Children.Add(modalView);

            window.Content = _grid;
        }
Beispiel #2
0
        public static void Detach(ModalView view)
        {
            var window = ApplicationHelpers.GetMainWindow();
            var grid   = (Grid)window.GetLogicalChildren().FirstOrDefault();

            grid?.Children.Remove(view);

            if (!_reserved)
            {
                return;
            }

            var originalChild = grid?.Children.FirstOrDefault();

            // this prevent exception: the control already has visual parent
            grid?.Children.Clear();
            window.Content = originalChild;
        }