Esempio 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;
        }
Esempio 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;
            }
        }
        /// <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"));
        }
Esempio 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;
        }
Esempio 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
            }
        }
Esempio 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;
 }
Esempio 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;
            }
        }
Esempio 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());
 }
Esempio n. 13
0
        public MainWindowViewModel(ISelectDirectoryService selectDirectoryService)
        {
            _listScreen = new ListViewModel(this, selectDirectoryService);
            _playerScreen = new PlayerViewModel(this);

            CurrentScreen = _listScreen;
        }
Esempio 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
            }
        }
Esempio n. 15
0
 public MainView()
 {
     InitializeComponent();
     vm = DataContext as IViewModel;
     vm.OnActivate();
     tabControl.SelectionChanged += Items_CurrentChanged;
 }
Esempio n. 16
0
 public void ReleaseViewModel(IViewModel viewModel)
 {
     if (viewModel != null)
     {
         ReleaseViewModelInstance(viewModel);
     }
 }
 /// <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;
 }
Esempio 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;
        }
Esempio 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);
 }
Esempio 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);
        }
Esempio 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;
        }
Esempio 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;
 }
Esempio 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;
 }
Esempio n. 26
0
 public Locator()
 {
     if (Windows.ApplicationModel.DesignMode.DesignModeEnabled)
         ViewModel = new FakeViewModel();
     else
         ViewModel = new ViewModel();
 }
Esempio n. 27
0
 public override void OnPropertyChanging(IViewModel viewModel, string propertyName, object oldValue)
 {
     OnPropertyChangingCalled = true;
     OnPropertyChangingViewModel = viewModel;
     OnPropertyChangingPropertyName = propertyName;
     OnPropertyChangingOldValue = oldValue;
 }
Esempio 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();
                                                       }
                                                   });
            }
        }
Esempio n. 29
0
 public static EventHandler SetContext(IViewModel viewModel)
 {
     return (o,e) =>
            	{
            		(o as FrameworkElement).DataContext = viewModel;
            	};
 }
Esempio 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);
        }
Esempio 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);
 }
Esempio 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)));
 }
Esempio 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);
 }
Esempio n. 34
0
 public static IAsyncOperation GetCurrentNavigationOperation([NotNull] this IViewModel viewModel)
 {
     Should.NotBeNull(viewModel, nameof(viewModel));
     return(viewModel.Settings.Metadata.GetData(ViewModelConstants.CurrentNavigationOperation));
 }
Esempio n. 35
0
 public static Guid GetViewModelId(this IViewModel viewModel)
 {
     return(ViewModelProvider.GetOrAddViewModelId(viewModel));
 }
Esempio n. 36
0
 public static void InvalidateCommands(this IViewModel viewModel)
 {
     Should.NotBeNull(viewModel, nameof(viewModel));
     viewModel.Publish(viewModel, StateChangedMessage.Empty);
 }
Esempio 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)));
 }
Esempio n. 38
0
 public static void RemoveClosedHandler([NotNull] this IViewModel viewModel, EventHandler <IViewModel, ViewModelClosedEventArgs> handler)
 {
     viewModel.UpdateEventHandler(ViewModelConstants.ClosedEvent, handler, false);
 }
Esempio n. 39
0
 public static IAsyncOperation ShowAsync([NotNull] this IViewModel viewModel, string viewName, IDataContext context = null)
 {
     return(viewModel.ShowAsync(null, viewName, context));
 }
Esempio 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)));
 }
Esempio n. 41
0
 public NavigationEventArgs(IViewModel viewModelToNavigateTo)
 {
     this.ViewModelToNavigateTo = viewModelToNavigateTo;
 }
Esempio 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)
 {
 }
Esempio n. 44
0
 public static IAsyncOperation ShowAsync([NotNull] this IViewModel viewModel, params DataConstantValue[] parameters)
 {
     return(viewModel.ShowAsync(parameters == null ? null : new DataContext(parameters)));
 }
Esempio 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)
 {
 }
Esempio 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();
            }
        }
 /// <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)
 {
 }
Esempio n. 49
0
 public virtual void OnViewModelChanged(IViewModel newValue)
 {
     Binder.Unbind();
     Binder.Bind(newValue);
 }
Esempio n. 50
0
 public void Register(IViewModel viewModel)
 {
     ViewModelList.Add(viewModel);
 }
Esempio n. 51
0
 public ViewModelPreservedEventArgs(IViewModel viewModel)
     : base(viewModel)
 {
 }
Esempio 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
 }
Esempio n. 53
0
        // -----


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

            base.ActivateItem(item);
        }
Esempio n. 54
0
 public Task Push(IViewModel viewModel, bool animated)
 {
     return(Push(_pagePresenter.Page(viewModel), viewModel, animated));
 }
Esempio n. 55
0
 public static bool?ShowModalWindow(Window view, IViewModel viewModel)
 {
     viewModel.Window = view;
     view.DataContext = viewModel;
     return(view.ShowDialog());
 }
Esempio n. 56
0
 /// <inheritdoc />
 public bool Predicate(IViewModel viewModel)
 {
     return(Key.IsInstanceOfType(viewModel));
 }
Esempio 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);
        }
Esempio n. 58
0
        public static bool?ShowModalWindow <TWindow>(IViewModel viewModel) where TWindow : Window, new()
        {
            var view = new TWindow();

            return(ShowModalWindow(view, viewModel));
        }
Esempio 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);
 }
Esempio n. 60
0
 public void BindModel(IViewModel <TestModel> vm)
 {
     BindModelCalled = true;
 }