public static ContainerWindow GetWindow(ContainerWindowViewModel vm)
 {
     if (!_windowDic.ContainsKey(vm))
     {
         return(null);
     }
     return(_windowDic[vm]);
 }
        public ContainerWindow(
            ContainerWindowViewModel vm,
            Func <ContainerWindow, UserControl> ucFactory,
            bool fixedSize = false,
            bool dragMove  = true)
        {
            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Save, Save_Executed, Save_Enabled));
            _fixedSize       = fixedSize;
            _uc              = ucFactory(this);
            vm.UcResourceDic = _uc.Resources;
            _vm              = vm;
            this.DataContext = _vm;
            if (vm.Height == 0 && vm.Width == 0)
            {
                this.SizeToContent = SizeToContent.WidthAndHeight;
            }
            else
            {
                if (vm.Height != 0)
                {
                    this.Height    = vm.Height;
                    this.MinHeight = vm.Height / 2;
                }
                if (vm.Width != 0)
                {
                    this.Width    = vm.Width;
                    this.MinWidth = vm.Width / 2;
                }
            }

            InitializeComponent();

            if (fixedSize)
            {
                if (!vm.IsDialogWindow)
                {
                    this.ResizeMode = ResizeMode.CanMinimize;
                }
                else
                {
                    this.ResizeMode = ResizeMode.NoResize;
                    vm.MinVisible   = Visibility.Collapsed;
                }
                vm.MaxVisible = Visibility.Collapsed;
            }
            if (dragMove)
            {
                this.MouseDown += (object sender, MouseButtonEventArgs e) => {
                    if (e.LeftButton == MouseButtonState.Pressed)
                    {
                        this.DragMove();
                    }
                };
            }
            this.Container.Children.Add(_uc);
        }
Example #3
0
        public static ContainerWindow ShowWindow <TUc>(
            ContainerWindowViewModel vm,
            Func <ContainerWindow, TUc> ucFactory,
            Action <UserControl> beforeShow = null,
            bool fixedSize = false) where TUc : UserControl
        {
            if (vm == null)
            {
                throw new ArgumentNullException(nameof(vm));
            }
            if (ucFactory == null)
            {
                throw new ArgumentNullException(nameof(ucFactory));
            }
            ContainerWindow window;
            Type            ucType = typeof(TUc);

            if (s_windowDicByType.ContainsKey(ucType))
            {
                window = s_windowDicByType[ucType];
            }
            else
            {
                window = new ContainerWindow(vm, ucFactory, fixedSize)
                {
                    WindowStartupLocation = WindowStartupLocation.Manual,
                    Owner = null
                };
                s_windowDic.Add(vm, window);
                if (!vm.IsDialogWindow)
                {
                    Windows.Add(vm);
                }
                s_windows.Add(vm);
                window.Closed += (object sender, EventArgs e) => {
                    s_windowDic.Remove(vm);
                    if (!vm.IsDialogWindow)
                    {
                        Windows.Remove(vm);
                    }
                    s_windows.Remove(vm);
                };
                s_windowDicByType.Add(ucType, window);
                if (s_windowLeftDic.ContainsKey(ucType))
                {
                    s_windowDicByType[ucType].Left = s_windowLeftDic[ucType];
                    s_windowDicByType[ucType].Top  = s_windowTopDic[ucType];
                }
                else
                {
                    s_windowDicByType[ucType].WindowStartupLocation = WindowStartupLocation.CenterScreen;
                }
            }
            window.ShowWindow(beforeShow);
            return(window);
        }
Example #4
0
        public static ContainerWindow ShowWindow <TUc>(
            ContainerWindowViewModel vm,
            Func <ContainerWindow, TUc> ucFactory,
            Action <ContainerWindow, TUc> beforeShow = null,
            Action afterClose = null,
            bool fixedSize    = false) where TUc : UserControl
        {
            if (vm == null)
            {
                throw new ArgumentNullException(nameof(vm));
            }
            if (ucFactory == null)
            {
                throw new ArgumentNullException(nameof(ucFactory));
            }
            ContainerWindow window = new ContainerWindow(vm, ucFactory, fixedSize);

            if (vm.IsMaskTheParent)
            {
                window.ShowWindow(beforeShow);
                return(window);
            }
            Type ucType = typeof(TUc);

            if (s_windowDicByType.ContainsKey(ucType))
            {
                window = s_windowDicByType[ucType];
            }
            else
            {
                s_windowDic.Add(vm, window);
                window.Closed += (object sender, EventArgs e) => {
                    s_windowDic.Remove(vm);
                    afterClose?.Invoke();
                };
                s_windowDicByType.Add(ucType, window);
                if (s_windowLeftDic.ContainsKey(ucType))
                {
                    window.WindowStartupLocation = WindowStartupLocation.Manual;
                    window.Left = s_windowLeftDic[ucType];
                    window.Top  = s_windowTopDic[ucType];
                }
            }
            window.ShowWindow(beforeShow);
            return(window);
        }
Example #5
0
        private ContainerWindow(
            ContainerWindowViewModel vm,
            Func <ContainerWindow, UserControl> ucFactory,
            Action afterClose,
            bool fixedSize = false)
        {
            _uc = ucFactory(this);
            vm.UcResourceDic = _uc.Resources;
            _vm = vm;
            this.DataContext = _vm;
            if (vm.Height == 0 && vm.Width == 0)
            {
                this.SizeToContent = SizeToContent.WidthAndHeight;
            }
            else
            {
                if (vm.Height == 0)
                {
                    this.SizeToContent = SizeToContent.Height;
                }
                else
                {
                    this.Height = vm.Height;
                    if (vm.MinHeight == 0)
                    {
                        this.MinHeight = vm.Height / 2;
                    }
                }
                if (vm.Width == 0)
                {
                    this.SizeToContent = SizeToContent.Width;
                }
                else
                {
                    this.Width = vm.Width;
                    if (vm.MinWidth == 0)
                    {
                        this.MinWidth = vm.Width / 2;
                    }
                }
            }
            if (vm.MinHeight != 0)
            {
                this.MinHeight = vm.MinHeight;
            }
            if (vm.MinWidth != 0)
            {
                this.MinWidth = vm.MinWidth;
            }

            InitializeComponent();
            this.TbUcName.Text = _uc.GetType().Name;
            this.Closed       += (object sender, EventArgs e) => {
                s_windowDic.Remove(vm);
                afterClose?.Invoke();
            };
            if (fixedSize)
            {
                if (vm.IsMaskTheParent)
                {
                    this.ResizeMode = ResizeMode.NoResize;
                }
                else
                {
                    this.ResizeMode = ResizeMode.CanMinimize;
                }
                vm.MaxVisible = Visibility.Collapsed;
            }
            this.Container.Children.Add(_uc);
        }
Example #6
0
 public ShowContainerWindowCommand(ContainerWindowViewModel vm)
 {
     this.Vm = vm;
 }
Example #7
0
        private ContainerWindow(
            ContainerWindowViewModel vm,
            Func <ContainerWindow, UserControl> ucFactory,
            bool fixedSize = false,
            bool dragMove  = true)
        {
            _uc = ucFactory(this);
            vm.UcResourceDic = _uc.Resources;
            _vm = vm;
            this.DataContext = _vm;
            if (vm.Height == 0 && vm.Width == 0)
            {
                this.SizeToContent = SizeToContent.WidthAndHeight;
            }
            else
            {
                if (vm.Height == 0)
                {
                    this.SizeToContent = SizeToContent.Height;
                }
                else
                {
                    this.Height = vm.Height;
                    if (vm.MinHeight == 0)
                    {
                        this.MinHeight = vm.Height / 2;
                    }
                }
                if (vm.Width == 0)
                {
                    this.SizeToContent = SizeToContent.Width;
                }
                else
                {
                    this.Width = vm.Width;
                    if (vm.MinWidth == 0)
                    {
                        this.MinWidth = vm.Width / 2;
                    }
                }
            }
            if (vm.MinHeight != 0)
            {
                this.MinHeight = vm.MinHeight;
            }
            if (vm.MinWidth != 0)
            {
                this.MinWidth = vm.MinWidth;
            }

            InitializeComponent();

            if (fixedSize)
            {
                if (vm.IsMaskTheParent)
                {
                    this.ResizeMode = ResizeMode.NoResize;
                }
                else
                {
                    this.ResizeMode = ResizeMode.CanMinimize;
                }
                vm.MaxVisible = Visibility.Collapsed;
            }
            if (dragMove)
            {
                this.MouseDown += (object sender, MouseButtonEventArgs e) => {
                    if (e.LeftButton == MouseButtonState.Pressed)
                    {
                        this.DragMove();
                    }
                };
            }
            this.Container.Children.Add(_uc);
        }