Ejemplo n.º 1
0
        private KeyValuePair<int, Window> CreateWindow(ViewModelType type, IViewModel viewModel)
        {
            this.index++;
            Window window;

            switch (type)
            {
                case ViewModelType.LoginWindow:
                    window = new LoginWindow {DataContext = viewModel};
                    break;
                case ViewModelType.MainWindow:
                    window = new MainWindow {DataContext = viewModel};
                    break;
                case ViewModelType.SettingsWindow:
                    window = new SettignsWindow { DataContext = viewModel };
                    break;
                default:
                    window = new Window { DataContext = viewModel };
                    break;
            }

            window.DataContext = viewModel;

            KeyValuePair<int, Window> keyValuePair = new KeyValuePair<int, Window>(this.index, window);
            this.windows.Add(keyValuePair);
            return keyValuePair;
        }
Ejemplo n.º 2
0
        public override void Add(ToolStripItem item, IViewModel viewModel)
        {
            if (_Items == null)
            {
                _Items = new List<ToolStripItem>();
            }

            _Items.Add(item);
            Pwd.M.ViewModel model = viewModel as Pwd.M.ViewModel;
            if (model == null)
            {
                return;
            }

            if (item is ToolStripMenuItem)
            {
                (item as ToolStripMenuItem).Checked = model.CatTreeVisible;
                return;
            }
            if (item is ToolStripButton)
            {
                (item as ToolStripButton).Checked = model.CatTreeVisible;
                return;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RibbonWindow"/> class.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        public RibbonWindow(IViewModel viewModel)
        {
            var viewModelType = (viewModel != null) ? viewModel.GetType() : GetViewModelType();
            if (viewModelType == null)
            {
                var viewModelLocator = ServiceLocator.Default.ResolveType<IViewModelLocator>();
                viewModelType = viewModelLocator.ResolveViewModel(GetType());
                if (viewModelType == null)
                {
                    const string error = "The view model of the view could not be resolved. Use either the GetViewModelType() method or IViewModelLocator";
                    throw new NotSupportedException(error);
                }
            }

            _logic = new WindowLogic(this, viewModelType, viewModel);
            _logic.ViewModelChanged += (sender, e) => ViewModelChanged.SafeInvoke(this, e);
            _logic.ViewModelPropertyChanged += (sender, e) => ViewModelPropertyChanged.SafeInvoke(this, e);
            _logic.PropertyChanged += (sender, e) => PropertyChanged.SafeInvoke(this, e);

            Loaded += (sender, e) => _viewLoaded.SafeInvoke(this);
            Unloaded += (sender, e) => _viewUnloaded.SafeInvoke(this);
            DataContextChanged += (sender, e) => _viewDataContextChanged.SafeInvoke(this, new DataContextChangedEventArgs(e.OldValue, e.NewValue));

            // Because the RadWindow does not close when DialogResult is set, the following code is required
            ViewModelChanged += (sender, e) => OnViewModelChanged();

            // Call manually the first time (for injected view models)
            OnViewModelChanged();

            SetBinding(TitleProperty, new Binding("Title"));
        }
Ejemplo n.º 4
0
 public int ShowWindow(ViewModelType type, IViewModel viewModel)
 {
     KeyValuePair<int, Window> k = this.CreateWindow(type, viewModel);
     viewModel.WindowId = k.Key;
     k.Value.Show();
     return k.Key;
 }
        public CreateItemViewModel(
            IViewModelsFactory<IItemOverviewStepViewModel> overviewVmFactory,
            IViewModelsFactory<IItemPropertiesStepViewModel> propertiesVmFactory,
            IViewModelsFactory<IItemPricingStepViewModel> pricingVmFactory,
            IViewModelsFactory<IEditorialReviewViewModel> reviewVmFactory,
            Item item, IViewModel parentEntityVM, ICatalogEntityFactory entityFactory)
        {
            _itemModel = new ItemStepModel
                {
                    InnerItem = item,
                    ParentEntityVM = parentEntityVM,
                    ParentWizard = this
                };

            var allParameters = new[] { new KeyValuePair<string, object>("itemModel", _itemModel) };

            // properties Step must be created first
            var propertiesStep = propertiesVmFactory.GetViewModelInstance(allParameters);
            // this step is created second, but registered first
            RegisterStep(overviewVmFactory.GetViewModelInstance(allParameters));
            RegisterEditorialReviewStep(item, entityFactory, reviewVmFactory);

            // properties Step is registered third
            RegisterStep(propertiesStep);

            pricingStep4 = pricingVmFactory.GetViewModelInstance(allParameters);
            // this step is added or removed at RUNTIME
            // RegisterStep(pricingStep4);

            item.StartDate = DateTime.Today;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Exports the <paramref name="viewModel" />'s view to the print or clipboard or file.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        /// <param name="exportMode">The export mode.</param>
        /// <param name="dpiX">The dpi X.</param>
        /// <param name="dpiY">The dpi Y.</param>
        /// <exception cref="System.InvalidOperationException"></exception>
        /// <exception cref="System.ArgumentNullException">The <paramref name="viewModel" /> is <c>null</c>.</exception>
        /// <remarks>If <paramref name="exportMode" /> is <see cref="ExportMode.Print" /> then the <paramref name="dpiX" /> and <paramref name="dpiY" /> argument will be ignored.</remarks>
        public virtual void Export(IViewModel viewModel, ExportMode exportMode = ExportMode.Print, double dpiX = 96, double dpiY = 96)
        {
            Argument.IsNotNull(() => viewModel);

            var view = _viewManager.GetViewsOfViewModel(viewModel).OfType<UIElement>().FirstOrDefault();
            if (view == null)
            {
                string message = string.Format(CultureInfo.InvariantCulture, "There no an active view for this view model of type '{0}'", viewModel.GetType().FullName);

                Log.Error(message);

                throw new InvalidOperationException(message);
            }

            if (exportMode == ExportMode.Print)
            {
                Print(view);
            }
            else
            {
                var bitmap = CreateImageFromUIElement(view, dpiX, dpiY);
#if !SILVERLIGHT 
                if (exportMode == ExportMode.File)
                {
                    SaveToFile(bitmap);
                }
                else
                {
                    Clipboard.SetImage(bitmap);
                }
#else
                SaveToFile(bitmap);
#endif
            }
        }
Ejemplo n.º 7
0
 protected WindowBase(IViewModel viewModel)
 {
     DataContext = viewModel;
     // Ghetto way to get CenterOwner to work...
     if (Application.Current.MainWindow != this)
         Owner = Application.Current.MainWindow;
 }
 private async void AsyncMethodWithViewModel(IAsyncOperation<bool> asyncOperation, bool result, IViewModel viewModel)
 {
     bool b = await asyncOperation;
     b.ShouldEqual(result);
     ViewModel = viewModel;
     AsyncMethodInvoked = true;
 }
Ejemplo n.º 9
0
        public override void Add(ToolStripItem item, IViewModel viewModel)
        {
            if (_Items == null)
            {
                _Items = new List<ToolStripItem>();
            }

            _Items.Add(item);
            Pwd.M.ViewModel model = viewModel as Pwd.M.ViewModel;
            if (model == null)
            {
                return;
            }

            bool ok = model.Pattern == CPwd.PATTERN_PRO;
            if (item is ToolStripMenuItem)
            {
                (item as ToolStripMenuItem).Checked = ok;
                return;
            }
            if (item is ToolStripButton)
            {
                (item as ToolStripButton).Checked = ok;
                return;
            }
        }
Ejemplo n.º 10
0
 public static void TraceViewModel(AuditAction auditAction, IViewModel viewModel)
 {
     Action<AuditAction, IViewModel> handler = TraceViewModelHandler;
     if (handler != null)
         handler(auditAction, viewModel);
     ServiceProvider.Tracer.TraceViewModel(auditAction, viewModel);
 }
        public void ActivateItem(IViewModel parentViewModel)
        {
            base.ActivateItem(parentViewModel);
            _activatedItems.Push(parentViewModel);

            Refresh();
        }
 public void CloseItem(IViewModel parentViewModel)
 {
     DeactivateItem(parentViewModel, true);
     _activatedItems.Pop();
     if (_activatedItems.Any())
         base.ActivateItem(_activatedItems.Peek());
 }
Ejemplo n.º 13
0
        public MainWindowViewModel(ISelectDirectoryService selectDirectoryService)
        {
            _listScreen = new ListViewModel(this, selectDirectoryService);
            _playerScreen = new PlayerViewModel(this);

            CurrentScreen = _listScreen;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Exports the <paramref name="viewModel" />'s view to the print or clipboard or file.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        /// <param name="exportMode">The export mode.</param>
        /// <param name="dpiX">The dpi X.</param>
        /// <param name="dpiY">The dpi Y.</param>
        /// <exception cref="System.InvalidOperationException"></exception>
        /// <exception cref="System.ArgumentNullException">The <paramref name="viewModel" /> is <c>null</c>.</exception>
        /// <remarks>If <paramref name="exportMode" /> is <see cref="ExportMode.Print" /> then the <paramref name="dpiX" /> and <paramref name="dpiY" /> argument will be ignored.</remarks>
        public virtual void Export(IViewModel viewModel, ExportMode exportMode = ExportMode.Print, double dpiX = 96, double dpiY = 96)
        {
            Argument.IsNotNull("viewModel", viewModel);

            var view = _viewManager.GetViewsOfViewModel(viewModel).OfType<UIElement>().FirstOrDefault();
            if (view == null)
            {
                throw Log.ErrorAndCreateException < InvalidOperationException >("There no an active view for this view model of type '{0}'", viewModel.GetType().FullName);
            }

            var bitmap = CreateImageFromUIElement(view, dpiX, dpiY);

            if (exportMode == ExportMode.Print)
            {
                Print(bitmap);
            }
            else
            {
#if !SILVERLIGHT 
                if (exportMode == ExportMode.File)
                {
                    SaveToFile(bitmap);
                }
                else
                {
                    Clipboard.SetImage(bitmap);
                }
#else
                SaveToFile(bitmap);
#endif
            }
        }
Ejemplo n.º 15
0
 public MainView()
 {
     InitializeComponent();
     vm = DataContext as IViewModel;
     vm.OnActivate();
     tabControl.SelectionChanged += Items_CurrentChanged;
 }
Ejemplo n.º 16
0
 public void ReleaseViewModel(IViewModel viewModel)
 {
     if (viewModel != null)
     {
         ReleaseViewModelInstance(viewModel);
     }
 }
Ejemplo n.º 17
0
 /// <summary>
 ///     Initializes the <see cref="NavigatedEventArgs" />.
 /// </summary>
 public NavigatedEventArgs([NotNull]INavigationContext context, [NotNull] IViewModel viewModel)
 {
     Should.NotBeNull(context, "context");
     Should.NotBeNull(viewModel, "viewModel");
     _context = context;
     _viewModel = viewModel;
 }
Ejemplo n.º 18
0
        public BindingExpression Create(IViewModel viewModel, String elementId, String targetProperty, Binding binding)
        {
            var type = viewModel.GetType();

            // find property dic
            IDictionary<string, MemberInfo> propertyDic;
            if(!_typeBindingDic.TryGetValue(type, out propertyDic))
            {
                propertyDic = new Dictionary<string, MemberInfo>();
                _typeBindingDic[type] = propertyDic;
            }

            MemberInfo propertyInfo = null;

            if(!propertyDic.TryGetValue(targetProperty, out propertyInfo))
            {
                // find the member...
                propertyInfo = type.GetMember(targetProperty).FirstOrDefault();

                if(propertyInfo == null)
                {
                    return null;
                }
                propertyDic[targetProperty] = propertyInfo;
            }
            var bindingExpression = new BindingExpression(binding, propertyInfo, viewModel);

            return bindingExpression;
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ViewModelCommandManager" /> class.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="viewModel"/> is <c>null</c>.</exception>
        private ViewModelCommandManager(IViewModel viewModel)
        {
            Argument.IsNotNull("viewModel", viewModel);

            Log.Debug("Creating a ViewModelCommandManager for view model '{0}' with unique identifier '{1}'", viewModel.GetType().FullName, viewModel.UniqueIdentifier);

            _viewModel = viewModel;
            _viewModelType = viewModel.GetType();
            _viewModel.Initialized += OnViewModelInitialized;
            _viewModel.PropertyChanged += OnViewModelPropertyChanged;
            _viewModel.Closed += OnViewModelClosed;

            var properties = new List<PropertyInfo>();
            properties.AddRange(_viewModelType.GetPropertiesEx());

            foreach (var propertyInfo in properties)
            {
                if (propertyInfo.PropertyType.ImplementsInterfaceEx(typeof(ICommand)))
                {
                    _commandProperties.Add(propertyInfo);
                }
            }

            RegisterCommands(false);

            Log.Debug("Created a ViewModelCommandManager for view model '{0}' with unique identifier '{1}'", viewModel.GetType().FullName, viewModel.UniqueIdentifier);
        }
 public VsDesignerControl(IViewModel viewModel)
 {
     DataContext = viewModel;
     InitializeComponent();
     // wait until we're initialized to handle events
     viewModel.ViewModelChanged += new EventHandler(ViewModelChanged);
 }
Ejemplo n.º 21
0
        public void Weave(UIElement view, IViewModel viewModel) {
            BindContext(view, viewModel);

            var namedElements = (view is ChildWindow ? GetChildWindowNamedElements(view) : GetNamedElements(view)).ToList();
            BindProperties(namedElements, viewModel);
            BindMethods(namedElements, viewModel);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ViewModelClosedEventArgs" /> class.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        /// <param name="result">The result to pass to the view. This will, for example, be used as <c>DialogResult</c>.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="viewModel"/> is <c>null</c>.</exception>
        public ViewModelClosedEventArgs(IViewModel viewModel, bool? result)
        {
            Argument.IsNotNull("viewModel", viewModel);

            ViewModel = viewModel;
            Result = result;
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CongregatePresenter"/> class.
 /// </summary>
 /// <param name="view">The view.</param>
 /// <param name="stockItemView">The stock item view.</param>
 /// <param name="bankAccountView">The bank account view.</param>
 /// <param name="model">The model.</param>
 public CongregatePresenter(ICongregateView view, IStockItemView stockItemView, IBankAccountView bankAccountView, IViewModel model)
 {
     this._View = view;
     this._StockItemView = stockItemView;
     this._BankAccountView = bankAccountView;
     this._Model = model as AppDataManager;
 }
Ejemplo n.º 24
0
 public override void OnPropertyChanged(IViewModel viewModel, string propertyName, object newValue)
 {
     OnPropertyChangedCalled = true;
     OnPropertyChangedViewModel = viewModel;
     OnPropertyChangedPropertyName = propertyName;
     OnPropertyChangedNewValue = newValue;
 }
 public void OnToggleViewCommand()
 {
     if (_CurrentViewModel.Equals(_CustomerListViewModel))
         CurrentViewModel = _CustomerViewModel;
     else
         CurrentViewModel = _CustomerListViewModel;
 }
Ejemplo n.º 26
0
 public Locator()
 {
     if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
         ViewModel = new FakeViewModel();
     else
         ViewModel = new ViewModel();
 }
Ejemplo n.º 27
0
 public override void OnPropertyChanging(IViewModel viewModel, string propertyName, object oldValue)
 {
     OnPropertyChangingCalled = true;
     OnPropertyChangingViewModel = viewModel;
     OnPropertyChangingPropertyName = propertyName;
     OnPropertyChangingOldValue = oldValue;
 }
Ejemplo n.º 28
0
        public void Initialise(IViewModel viewModel)
        {
            ViewModel = viewModel;

            var supportClosing = ViewModel as ISupportClosing;
            if (supportClosing != null)
            {
                ShowClose = true;

                IDisposable closing = null;
                closing = supportClosing.ClosingStrategy.Closed
                                        .Subscribe(x =>
                                                   {
                                                       if (!_viewModelIsClosed)
                                                       {
                                                           _viewModelIsClosed = true;
                                                           ClosingStrategy.Close();
                                                       }

                                                       if (closing != null)
                                                       {
                                                           closing.Dispose();
                                                       }
                                                   });
            }
        }
Ejemplo n.º 29
0
 public static EventHandler SetContext(IViewModel viewModel)
 {
     return (o,e) =>
            	{
            		(o as FrameworkElement).DataContext = viewModel;
            	};
 }
Ejemplo n.º 30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WindowLogic"/> class.
        /// </summary>
        /// <param name="targetWindow">The window this provider should take care of.</param>
        /// <param name="viewModelType">Type of the view model.</param>
        /// <param name="viewModel">The view model to inject.</param>
        /// <exception cref="ArgumentNullException">The <paramref name="targetWindow"/> is <c>null</c>.</exception>
        public WindowLogic(IView targetWindow, Type viewModelType = null, IViewModel viewModel = null)
            : base(targetWindow, viewModelType, viewModel)
        {
            var targetWindowType = targetWindow.GetType();

            string eventName;

            var closedEvent = targetWindowType.GetEventEx("Closed");
            if (closedEvent != null)
            {
                eventName = "Closed";

                _dynamicEventListener = new DynamicEventListener(targetWindow, "Closed", this, "OnTargetWindowClosed");
            }
            else
            {
                eventName = "Unloaded";

                _dynamicEventListener = new DynamicEventListener(targetWindow, "Unloaded", this, "OnTargetWindowClosed");
            }

            _targetWindowClosedEventName = eventName;

            Log.Debug("Using '{0}.{1}' event to determine window closing", targetWindowType.FullName, eventName);
        }
Ejemplo n.º 31
0
 /// <summary>
 /// Registers a view model instance with the manager. All view models must register themselves to the manager.
 /// </summary>
 /// <param name="viewModel">The view model to register.</param>
 /// <exception cref="ArgumentNullException">The <paramref name="viewModel"/> is <c>null</c>.</exception>
 public void RegisterViewModelInstance(IViewModel viewModel)
 {
     RegisterViewModelInstanceInternal(viewModel);
 }
Ejemplo n.º 32
0
 public static IViewModel GetViewModel([NotNull] this IViewModelProvider viewModelProvider, [NotNull] Type viewModelType, IViewModel parentViewModel = null,
                                       ObservationMode?observationMode = null, params DataConstantValue[] parameters)
 {
     return(GetViewModel(viewModelProvider, viewModelType, MergeParameters(parentViewModel, observationMode, parameters)));
 }
Ejemplo n.º 33
0
 public static IViewModel GetParentViewModel([NotNull] this IViewModel viewModel)
 {
     Should.NotBeNull(viewModel, nameof(viewModel));
     return((IViewModel)viewModel.Settings.Metadata.GetData(ViewModelConstants.ParentViewModel)?.Target);
 }
Ejemplo n.º 34
0
 public static IAsyncOperation GetCurrentNavigationOperation([NotNull] this IViewModel viewModel)
 {
     Should.NotBeNull(viewModel, nameof(viewModel));
     return(viewModel.Settings.Metadata.GetData(ViewModelConstants.CurrentNavigationOperation));
 }
Ejemplo n.º 35
0
 public static Guid GetViewModelId(this IViewModel viewModel)
 {
     return(ViewModelProvider.GetOrAddViewModelId(viewModel));
 }
Ejemplo n.º 36
0
 public static void InvalidateCommands(this IViewModel viewModel)
 {
     Should.NotBeNull(viewModel, nameof(viewModel));
     viewModel.Publish(viewModel, StateChangedMessage.Empty);
 }
Ejemplo n.º 37
0
 public static T GetViewModel <T>([NotNull] this IViewModelProvider viewModelProvider,
                                  IViewModel parentViewModel = null, ObservationMode?observationMode = null, params DataConstantValue[] parameters) where T : IViewModel
 {
     return(GetViewModel <T>(viewModelProvider, MergeParameters(parentViewModel, observationMode, parameters)));
 }
Ejemplo n.º 38
0
 public static void RemoveClosedHandler([NotNull] this IViewModel viewModel, EventHandler <IViewModel, ViewModelClosedEventArgs> handler)
 {
     viewModel.UpdateEventHandler(ViewModelConstants.ClosedEvent, handler, false);
 }
Ejemplo n.º 39
0
 public static IAsyncOperation ShowAsync([NotNull] this IViewModel viewModel, string viewName, IDataContext context = null)
 {
     return(viewModel.ShowAsync(null, viewName, context));
 }
Ejemplo n.º 40
0
 public static T GetViewModel <T>([NotNull] this IViewModelProvider viewModelProvider,
                                  [NotNull] GetViewModelDelegate <T> getViewModelGeneric, IViewModel parentViewModel = null,
                                  ObservationMode?observationMode = null, params DataConstantValue[] parameters) where T : class, IViewModel
 {
     return(GetViewModel(viewModelProvider, getViewModelGeneric, MergeParameters(parentViewModel, observationMode, parameters)));
 }
Ejemplo n.º 41
0
 public NavigationEventArgs(IViewModel viewModelToNavigateTo)
 {
     this.ViewModelToNavigateTo = viewModelToNavigateTo;
 }
Ejemplo n.º 42
0
 public static void AddClosingHandler([NotNull] this IViewModel viewModel, EventHandler <IViewModel, ViewModelClosingEventArgs> handler)
 {
     viewModel.UpdateEventHandler(ViewModelConstants.ClosingEvent, handler, true);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FooViewModelView"/> class.
 /// </summary>
 /// <param name="viewModel">
 /// The view model.
 /// </param>
 public FooViewModelView(IViewModel viewModel)
     : base(viewModel)
 {
 }
Ejemplo n.º 44
0
 public static IAsyncOperation ShowAsync([NotNull] this IViewModel viewModel, params DataConstantValue[] parameters)
 {
     return(viewModel.ShowAsync(parameters == null ? null : new DataContext(parameters)));
 }
Ejemplo n.º 45
0
 public void ChangeCurrentView(ViewBase newView, IViewModel sender)
 {
     CurrentView = newView;
     UpdateCurrentView(sender);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FooParentViewModelView"/> class.
 /// </summary>
 /// <param name="viewModel">
 /// The view model.
 /// </param>
 public FooParentViewModelView(IViewModel viewModel)
     : base(viewModel)
 {
 }
Ejemplo n.º 47
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DataWindow"/> class.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        /// <param name="mode"><see cref="DataWindowMode"/>.</param>
        /// <param name="additionalButtons">The additional buttons.</param>
        /// <param name="defaultButton">The default button.</param>
        /// <param name="setOwnerAndFocus">if set to <c>true</c>, set the main window as owner window and focus the window.</param>
        /// <param name="infoBarMessageControlGenerationMode">The info bar message control generation mode.</param>
        /// <param name="focusFirstControl">if set to <c>true</c>, the first control will get the focus.</param>
        public DataWindow(IViewModel viewModel, DataWindowMode mode, IEnumerable <DataWindowButton> additionalButtons = null,
                          DataWindowDefaultButton defaultButton = DataWindowDefaultButton.OK, bool setOwnerAndFocus = true,
                          InfoBarMessageControlGenerationMode infoBarMessageControlGenerationMode = InfoBarMessageControlGenerationMode.Inline, bool focusFirstControl = true)
        {
            if (CatelEnvironment.IsInDesignMode)
            {
                return;
            }

            // Set window style (WPF doesn't allow styling on root elements of XAML files, too bad)
            // For more info, see http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/3059c0e4-c372-4da2-b384-28f271feef05/
            SetResourceReference(StyleProperty, typeof(DataWindow));

            Mode          = mode;
            DefaultButton = defaultButton;
            _infoBarMessageControlGenerationMode = infoBarMessageControlGenerationMode;

            this.FixBlurriness();

            SizeToContent         = SizeToContent.WidthAndHeight;
            ShowInTaskbar         = false;
            ResizeMode            = ResizeMode.NoResize;
            WindowStartupLocation = WindowStartupLocation.CenterOwner;

            this.ApplyIconFromApplication();

            ThemeHelper.EnsureCatelMvvmThemeIsLoaded();

            _logic = new WindowLogic(this, null, viewModel);
            _logic.TargetViewPropertyChanged += (sender, e) =>
            {
                // Do not call this for ActualWidth and ActualHeight WPF, will cause problems with NET 40
                // on systems where NET45 is *not* installed
                if (!string.Equals(e.PropertyName, nameof(ActualWidth), StringComparison.InvariantCulture) &&
                    !string.Equals(e.PropertyName, nameof(ActualHeight), StringComparison.InvariantCulture))
                {
                    PropertyChanged?.Invoke(this, e);
                }
            };

            _logic.ViewModelClosedAsync += OnViewModelClosedAsync;
            _logic.ViewModelChanged     += (sender, e) => RaiseViewModelChanged();

            _logic.ViewModelPropertyChanged += (sender, e) =>
            {
                OnViewModelPropertyChanged(sender, e);

                ViewModelPropertyChanged?.Invoke(this, e);
            };

            Loaded += (sender, e) =>
            {
                _viewLoaded?.Invoke(this, EventArgs.Empty);

                OnLoaded(e);
            };

            Unloaded += (sender, e) =>
            {
                _viewUnloaded?.Invoke(this, EventArgs.Empty);

                OnUnloaded(e);
            };

            SetBinding(TitleProperty, new Binding("Title"));

            if (additionalButtons != null)
            {
                foreach (var button in additionalButtons)
                {
                    _buttons.Add(button);
                }
            }

            CanClose            = true;
            CanCloseUsingEscape = true;

            Loaded             += (sender, e) => Initialize();
            DataContextChanged += (sender, e) => _viewDataContextChanged?.Invoke(this, new DataContextChangedEventArgs(e.OldValue, e.NewValue));

            // #1150 Subscribe in dispatcher to allow derived types to be the first handler
            Dispatcher.BeginInvoke(() =>
            {
                Closing += OnDataWindowClosing;
            });

            _focusFirstControl = focusFirstControl;

            if (setOwnerAndFocus)
            {
                this.SetOwnerWindowAndFocus(focusFirstControl: focusFirstControl);
            }
            else if (focusFirstControl)
            {
                this.FocusFirstControl();
            }
        }
Ejemplo n.º 48
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="NotifyPropertyChangedBase" /> class.
 /// </summary>
 public WindowViewMediator([NotNull] IViewModel viewModel, [NotNull] IThreadManager threadManager,
                           [NotNull] IViewManager viewManager, [NotNull] IOperationCallbackManager callbackManager)
     : base(viewModel, threadManager, viewManager, callbackManager)
 {
 }
Ejemplo n.º 49
0
 public virtual void OnViewModelChanged(IViewModel newValue)
 {
     Binder.Unbind();
     Binder.Bind(newValue);
 }
Ejemplo n.º 50
0
 public void Register(IViewModel viewModel)
 {
     ViewModelList.Add(viewModel);
 }
Ejemplo n.º 51
0
 public ViewModelPreservedEventArgs(IViewModel viewModel)
     : base(viewModel)
 {
 }
Ejemplo n.º 52
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DataWindow"/> class.
 /// </summary>
 /// <param name="viewModel">The view model.</param>
 /// <remarks>
 /// Explicit constructor with view model injection, required for <see cref="Activator.CreateInstance(System.Type)"/> which
 /// does not seem to support default parameter values.
 /// </remarks>
 public DataWindow(IViewModel viewModel)
     : this(viewModel, DataWindowMode.OkCancel)
 {
     // Do not remove this constructor, see remarks
 }
Ejemplo n.º 53
0
        // -----


        public override void ActivateItem(IViewModel item)
        {
            Title = item.WindowTitle;

            base.ActivateItem(item);
        }
Ejemplo n.º 54
0
 public Task Push(IViewModel viewModel, bool animated)
 {
     return(Push(_pagePresenter.Page(viewModel), viewModel, animated));
 }
Ejemplo n.º 55
0
 public static bool?ShowModalWindow(Window view, IViewModel viewModel)
 {
     viewModel.Window = view;
     view.DataContext = viewModel;
     return(view.ShowDialog());
 }
Ejemplo n.º 56
0
 /// <inheritdoc />
 public bool Predicate(IViewModel viewModel)
 {
     return(Key.IsInstanceOfType(viewModel));
 }
Ejemplo n.º 57
0
        /// <summary>
        ///     Shows a window that is registered with the specified view model in a non-modal state.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        /// <param name="completedProc">
        ///     The callback procedure that will be invoked as soon as the window is closed. This value can
        ///     be <c>null</c>.
        /// </param>
        /// <returns>
        ///     <c>true</c> if the popup window is successfully opened; otherwise <c>false</c>.
        /// </returns>
        /// <exception cref="ArgumentNullException">The <paramref name="viewModel" /> is <c>null</c>.</exception>
        /// <exception cref="WindowNotRegisteredException">
        ///     The <paramref name="viewModel" /> is not registered by the
        ///     <see cref="Register(string,System.Type,bool)" /> method first.
        /// </exception>
        public async Task <bool?> ShowAsync(IViewModel viewModel, EventHandler <UICompletedEventArgs> completedProc = null)
        {
            Argument.IsNotNull(nameof(viewModel), viewModel);

            bool?result        = null;
            var  viewModelType = viewModel.GetType();
            var  resolvedView  = _viewLocator.ResolveView(viewModelType);
            var  view          = (View)_typeFactory.CreateInstance(resolvedView);

            if (view is IView)
            {
                (view as IView).DataContext = viewModel;
            }
            else
            {
                view.BindingContext = viewModel;
            }

            var okButton = new Button
            {
                Text = _languageService.GetString("OK")
            };

            okButton.Clicked += (sender, args) =>
            {
                result = true;
                OnOkButtonClicked(viewModel, completedProc);
            };

            var cancelButton = new Button
            {
                Text = _languageService.GetString("Cancel")
            };

            cancelButton.Clicked += (sender, args) =>
            {
                result = false;
                OnCancelButtonClicked(viewModel, completedProc);
            };

            var dataErrorInfo = viewModel as INotifyDataErrorInfo;

            if (dataErrorInfo != null)
            {
                Action checkIfViewModelHasErrors = () => okButton.IsEnabled = !dataErrorInfo.HasErrors;
                viewModel.PropertyChanged += (sender, args) => checkIfViewModelHasErrors();
                checkIfViewModelHasErrors();
            }

            ////TODO: Improve the layout.
            var buttonsStackLayout = new StackLayout
            {
                Orientation       = StackOrientation.Horizontal,
                HorizontalOptions = LayoutOptions.Center
            };

            buttonsStackLayout.Children.Add(okButton);
            buttonsStackLayout.Children.Add(cancelButton);

            var contentLayout = new StackLayout();

            contentLayout.Children.Add(view);
            contentLayout.Children.Add(buttonsStackLayout);

            if (!await TryDisplayAsPopupAsync(viewModel, completedProc, contentLayout))
            {
                await DisplayUsingNavigationAsync(viewModel, completedProc, contentLayout);
            }

            return(result);
        }
Ejemplo n.º 58
0
        public static bool?ShowModalWindow <TWindow>(IViewModel viewModel) where TWindow : Window, new()
        {
            var view = new TWindow();

            return(ShowModalWindow(view, viewModel));
        }
Ejemplo n.º 59
0
 /// <summary>
 ///     Shows a window that is registered with the specified view model in a non-modal state.
 /// </summary>
 /// <param name="viewModel">The view model.</param>
 /// <param name="completedProc">
 ///     The callback procedure that will be invoked as soon as the window is closed. This value can
 ///     be <c>null</c>.
 /// </param>
 /// <returns>
 ///     <c>true</c> if the popup window is successfully opened; otherwise <c>false</c>.
 /// </returns>
 /// <exception cref="ArgumentNullException">The <paramref name="viewModel" /> is <c>null</c>.</exception>
 /// <exception cref="WindowNotRegisteredException">
 ///     The <paramref name="viewModel" /> is not registered by the
 ///     <see cref="Register(string,System.Type,bool)" /> method first.
 /// </exception>
 public bool?Show(IViewModel viewModel, EventHandler <UICompletedEventArgs> completedProc = null)
 {
     return(ShowAsync(viewModel, completedProc).Result);
 }
Ejemplo n.º 60
0
 public void BindModel(IViewModel <TestModel> vm)
 {
     BindModelCalled = true;
 }