示例#1
0
 public void Show(IWindowViewModel vm)
 {
     if (GetView(vm) is Window window)
     {
         window.Show();
     }
 }
示例#2
0
        private void ShowWindowDialog_Closed(object a_sender, EventArgs a_e)
        {
            Window           window    = (Window)a_sender;
            IWindowViewModel viewModel = (IWindowViewModel)window.DataContext;

            viewModel.WindowClosed();

            viewModel.WindowView = null;
            window.Closing      -= ShowWindowDialog_Closing;
            window.Closed       -= ShowWindowDialog_Closed;

            Action closeAction = window.Tag as Action;

            if (closeAction != null)
            {
                closeAction();
                window.Tag = null;
            }

            // Remove the VM.
            IViewFor viewFor = window as IViewFor;

            if (viewFor != null)
            {
                viewFor.ViewModel = null;
            }
        }
        /// <inheritdoc />
        public async Task <bool> OpenWindowAsync(IWindowViewModel viewModel, string windowId)
        {
            var coordinator = CoordinatorFactory.Create(viewModel);

            Log.Debug($"Opening window {viewModel.GetType().FullName}");
            return(await coordinator.DisplayAsync(viewModel, new WindowArguments(windowId ?? Guid.NewGuid().ToString())));
        }
示例#4
0
        public void ShowDialog(IWindowViewModel viewModel, ResizeMode resizeMode)
        {
            viewModel.Closed = false;
            ClosableWindow window = CreateWindow(viewModel, resizeMode);

            window.OpenDialog();
        }
        public void Show(IWindowViewModel windowViewModel)
        {
            if (windowViewModel == null)
            {
                throw new ArgumentNullException(nameof(windowViewModel));
            }

            CreateWindow(windowViewModel).Show();
        }
        private Window CreateWindow(IWindowViewModel windowViewModel)
        {
            var window = (Window)Activator.CreateInstance(m_viewMapping[windowViewModel.GetType()]);

            window.DataContext = windowViewModel;
            window.Loaded     += (sender, args) => windowViewModel.OnViewIsLoaded();
            window.Closed     += (sender, args) => windowViewModel.OnViewIsClosed();

            return(window);
        }
示例#7
0
        public bool?OpenDialog(IWindowViewModel viewModel, bool allowResize, double?width, double?height)
        {
            Window window = CreateWindow(viewModel, allowResize, width, height);

            // Do not show dialog in taskbar
            window.ShowInTaskbar = false;
            // Register KeyDown event
            window.PreviewKeyDown += Window_PreviewKeyDown;
            // Show window
            return(window.ShowDialog());
        }
示例#8
0
        public void CloseWindow(IWindowViewModel viewModel, bool result)
        {
            Window window = _openWindows.FirstOrDefault(w => w.DataContext == viewModel);

            if (window != null)
            {
                //window.Close();
                window.DialogResult = result;
                _openWindows.Remove(window);
            }
        }
示例#9
0
        private void ShowWindowDialog_Closing(object a_sender, CancelEventArgs a_e)
        {
            Window           window    = (Window)a_sender;
            IWindowViewModel viewModel = window.DataContext as IWindowViewModel;

            if (viewModel == null)
            {
                return;
            }

            a_e.Cancel = !viewModel.WindowIsClosing();
        }
示例#10
0
 public Task <TResult> ShowDialog <TResult>(IWindowViewModel vm)
 {
     if (GetView(vm) is Window window)
     {
         Window owner = LightApplicationBase.MainWindow ?? window;
         if (owner != window)
         {
             return(window.ShowDialog <TResult>(owner));
         }
     }
     return(null);
 }
        /// <summary>
        /// Creates a WPF Window object with an attached ViewModel. Offers the option to enable/disable event handlers.
        /// </summary>
        /// <param name="window">The XAML markup object the viewmodel is to be mapped to.</param>
        /// <param name="windowViewModel">The object assigned to the window as a ViewModel.</param>
        /// <param name="hasEventHandlers">Indicates whether or not the ViewModel has control over window state.</param>
        public WindowInitializer(Window window, IWindowViewModel windowViewModel, bool hasEventHandlers)
        {
            _window = window;
            _windowViewModel = windowViewModel;

            if (hasEventHandlers)
            {
                _windowViewModel.PropertyChanged += windowViewModel_PropertyChanged;
            }

            window.DataContext = _windowViewModel;
        }
示例#12
0
        private Window CreateWindow(IWindowViewModel viewModel, bool allowResize, double?width, double?height)
        {
            Window window = new Window();

            try
            {
                window.Owner = Application.Current.MainWindow;
                window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            }
            catch
            {
                window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            }

            window.ResizeMode    = allowResize ? ResizeMode.CanResizeWithGrip : ResizeMode.NoResize;
            window.WindowStyle   = WindowStyle.SingleBorderWindow;
            window.ShowInTaskbar = true;

            if (width != null && height != null)
            {
                window.SizeToContent = SizeToContent.Manual;
                window.Width         = width.Value;
                window.Height        = height.Value;
            }
            else
            {
                window.SizeToContent = SizeToContent.WidthAndHeight;
            }

            window.Content     = viewModel;
            window.DataContext = viewModel;

            window.ResizeMode = allowResize ? ResizeMode.CanResizeWithGrip : ResizeMode.NoResize;

            // Bind window title
            if (string.IsNullOrEmpty(window.Title))
            {
                window.SetBinding(Window.TitleProperty, nameof(IWindowViewModel.DisplayName));
            }

            // The WindowManager will always live longer than the window,
            // so we don't need to unsubscribe this event handler.
            window.Closed += Window_Closed;

            // Add to open windows
            _openWindows.Add(window);

            return(window);
        }
示例#13
0
        private void ShowWindow(IViewModel a_ownerViewModel, IWindowViewModel a_viewModel, Window a_dialog, Action a_windowClosedCallback)
        {
            // Create dialog and set properties
            a_dialog.DataContext = a_viewModel;
            a_dialog.Owner       = a_ownerViewModel != null?FindOwnerWindow(a_ownerViewModel) : null;

            // Bind the closing event to the viewmodel.
            a_dialog.Closing      += ShowWindowDialog_Closing;
            a_dialog.Closed       += ShowWindowDialog_Closed;
            a_dialog.Tag           = a_windowClosedCallback;
            a_viewModel.WindowView = a_dialog as IWindowView;

            // Show dialog
            a_dialog.Show();
        }
示例#14
0
 public void Close(IWindowViewModel vm)
 {
     if (GetView(vm) is Window window)
     {
         // remove view first
         viewStore.Remove(vm);
         if (vm.DialogResult != null)
         {
             window.Close(vm.DialogResult);
         }
         else
         {
             window.Close();
         }
     }
 }
示例#15
0
        private ClosableWindow CreateWindow(IWindowViewModel viewModel, ResizeMode resizeMode)
        {
            System.Windows.ResizeMode mode = GetMode(resizeMode);
            var window = new ClosableWindow(viewModel, mode);

            if (ownerWindow != null)
            {
                window.Owner = ownerWindow;
                window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            }
            else if (ownerForm != null)
            {
                var helper = new WindowInteropHelper(window);
                helper.Owner = ownerForm.Handle;
                window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            }

            return(window);
        }
示例#16
0
        private void ShowWindow(IWindowViewModel vm, Window w, bool setOwner)
        {
            if (setOwner)
            {
                w.Owner = this;
            }

            w.DataContext = vm;
            w.Closed     += (s, e) =>
            {
                vm.IsClosed = true;
            };
            var path = new PropertyPath(typeof(IWindowViewModel).GetProperty("IsActive"));

            w.SetBinding(ActivateBehavior.IsActiveProperty, new Binding()
            {
                Path = path
            });
            w.Show();
        }
示例#17
0
 public void SetSizeAndPosition(IWindowViewModel viewModel, Rect rect)
 {
   Window window = m_views.First(n => ReferenceEquals(n.DataContext, viewModel)) as Window;
   if (window == null) return;
   window.Left = rect.X;
   window.Top = rect.Y;
   window.Width = rect.Width;
   window.Height = rect.Height;
 }
示例#18
0
        public void OpenWindow(IWindowViewModel viewModel, bool allowResize, double?width, double?height)
        {
            Window window = CreateWindow(viewModel, allowResize, width, height);

            window.Show();
        }
 /// <summary>
 /// Creates a WPF Window object with an attached ViewModel.
 /// </summary>
 /// <param name="window">The XAML markup object the viewmodel is to be mapped to.</param>
 /// <param name="windowViewModel">The object assigned to the window as a ViewModel.</param>
 public WindowInitializer(Window window, IWindowViewModel windowViewModel)
     : this(window, windowViewModel, true)
 {
 }
示例#20
0
 public void CloseWindow(IWindowViewModel viewModel)
 {
     CloseWindow(viewModel, true);
 }
示例#21
0
 public void OpenWindow(IWindowViewModel viewModel, bool allowResize)
 {
 }
示例#22
0
 public void OpenWindow(IWindowViewModel viewModel, bool allowResize, double?width, double?height)
 {
 }
示例#23
0
 public Rect GetSizeAndPosition(IWindowViewModel viewModel)
 {
   Window window = m_views.First(n => ReferenceEquals(n.DataContext, viewModel)) as Window;
   if (window == null) return default(Rect);
   return new Rect(window.Left, window.Top, window.Width, window.Height);
 }
示例#24
0
 public void OpenWindow(IWindowViewModel viewModel)
 {
 }
示例#25
0
 public bool?OpenDialog(IWindowViewModel viewModel, bool allowResize)
 {
     return(OpenDialog(viewModel, allowResize, null, null));
 }
示例#26
0
 public void CloseDialog(IWindowViewModel viewModel)
 {
   List<FrameworkElement> windowsToClose = m_views.Where(n => ReferenceEquals(n.DataContext, viewModel)).ToList();
   foreach (Window window in windowsToClose)
   {
     window.Close();
   }
 }
示例#27
0
 public void OpenWindow(IWindowViewModel viewModel)
 {
     OpenWindow(viewModel, true);
 }
 public ApplicationViewModel(IWindowViewModel window, NavigationViewModel router)
 {
     Window              = window;
     Router              = router;
     Router.OnNavigated += Router_OnNavigated;
 }
示例#29
0
 public void ShowWindow(IWindowViewModel viewModel, Rect? rect = null)
 {
   if (!m_rootView.View.Dispatcher.CheckAccess())
   {
     m_rootView.View.Dispatcher.Invoke(() => ShowWindow(viewModel, rect));
     return;
   }
   Window dialog = Activator.CreateInstance(viewModel.WindowsType) as Window;
   if (dialog == null)
     throw new ArgumentException("viewType must be of type Window");
   dialog.DataContext = viewModel;
   Register(dialog);
   if (rect != null)
     SetSizeAndPosition(viewModel, (Rect)rect);
   dialog.Show();
 }
示例#30
0
 public void OpenWindow(IWindowViewModel viewModel, bool allowResize)
 {
     OpenWindow(viewModel, allowResize, null, null);
 }
示例#31
0
 public bool?OpenDialog(IWindowViewModel viewModel) => false;
示例#32
0
 public bool?OpenDialog(IWindowViewModel viewModel)
 {
     return(OpenDialog(viewModel, true));
 }
示例#33
0
 public bool?OpenDialog(IWindowViewModel viewModel, bool allowResize) => false;
示例#34
0
 public bool?OpenDialog(IWindowViewModel viewModel, bool allowResize, double?width, double?height) => false;
示例#35
0
    public void BringToFront(IWindowViewModel viewModel)
    {
      Application.Current.Dispatcher.Invoke(() => BringToFront(FindOwner(viewModel)));

    }
示例#36
0
 public ApplicationViewModel(IWindowViewModel window, NavigationViewModel router)
 {
     Window = window;
     Router = router;
 }
示例#37
0
 public void CloseWindow(IWindowViewModel viewModel, bool result)
 {
 }