internal static void Show_AddIngredientsView(Dishes dish) { Show_WaitView("Cargando las lista de productos"); //TODO select all products from db List <Products> products; using (var db = App.DbFactory.Open()) { products = db.Select <Products>(); } Current.Dispatcher.Invoke(() => { ParentView.Current.ProductCatalogBtn.IsEnabled = false; ParentView.Current.DishesCatalogBtn.IsEnabled = false; ParentView.Current.ConfigurationBtn.IsEnabled = false; var oldView = Current.Transition.Content as UserControl; var view = new AddIngredientsView(dish, products); Current.Transition.Content = view; ViewLoaded?.Invoke(view); App.Log.Message($"AddIngredientsView. Dish: {dish.ToString()}\nProducts: {products.Serialize(LibreR.Models.Enums.Serializer.OneLine)}", "VIEW-LOADED"); if (!(oldView is WaitView)) { ViewUnloaded?.Invoke(oldView); } }); }
internal static void Show_DishesView() { Show_WaitView("Cargando el catálogo de platillos"); //TODO select all dishes from db List <Dishes> dishes; using (var db = App.DbFactory.Open()) { dishes = db.Select <Dishes>(); } Current.Dispatcher.Invoke(() => { ParentView.Current.ProductCatalogBtn.IsEnabled = true; ParentView.Current.DishesCatalogBtn.IsEnabled = true; ParentView.Current.ConfigurationBtn.IsEnabled = true; var oldView = Current.Transition.Content as UserControl; var view = new DishesView(dishes); Current.Transition.Content = view; ViewLoaded?.Invoke(view); App.Log.Message($"DishesView", "VIEW-LOADED"); if (!(oldView is WaitView)) { ViewUnloaded?.Invoke(oldView); } }); }
/// <summary> /// Initializes a new instance of the <see cref="UIViewController"/> class. /// </summary> public UIViewController() { if (CatelEnvironment.IsInDesignMode) { return; } var viewModelType = GetViewModelType(); if (viewModelType is null) { Log.Debug("GetViewModelType() returned null, using the ViewModelLocator to resolve the view model"); viewModelType = _viewModelLocator.ResolveViewModel(GetType()); if (viewModelType is null) { const string error = "The view model of the view could not be resolved. Use either the GetViewModelType() method or IViewModelLocator"; Log.Error(error); throw new NotSupportedException(error); } } _logic = new PageLogic(this, viewModelType); _logic.TargetViewPropertyChanged += (sender, e) => { OnPropertyChanged(e); PropertyChanged?.Invoke(this, e); }; _logic.ViewModelChanged += (sender, e) => RaiseViewModelChanged(); _logic.ViewModelPropertyChanged += (sender, e) => { OnViewModelPropertyChanged(e); ViewModelPropertyChanged?.Invoke(this, e); }; _logic.DetermineViewModelInstance += (sender, e) => { e.ViewModel = GetViewModelInstance(e.DataContext); }; _logic.DetermineViewModelType += (sender, e) => { e.ViewModelType = GetViewModelType(e.DataContext); }; _logic.ViewLoading += (sender, e) => ViewLoading?.Invoke(this); _logic.ViewLoaded += (sender, e) => ViewLoaded?.Invoke(this); _logic.ViewUnloading += (sender, e) => ViewUnloading?.Invoke(this); _logic.ViewUnloaded += (sender, e) => ViewUnloaded?.Invoke(this); }
/// <summary> /// Initializes a new instance of the <see cref="RoomView"/> class. /// </summary> /// <remarks> /// The <see cref="IViewModelContainer"/> is implemented to enable chained user controls for validation. This /// means that only the top-level view model has to invoke Validate to validate all child view models. /// </remarks> public RoomView() { InitializeComponent(); mvvmBehavior.ViewModelChanged += (sender, e) => ViewModelChanged.SafeInvoke(this, e); mvvmBehavior.ViewModelPropertyChanged += (sender, e) => ViewModelPropertyChanged.SafeInvoke(this, e); mvvmBehavior.ViewLoading += (sender, e) => ViewLoading.SafeInvoke(this); mvvmBehavior.ViewLoaded += (sender, e) => ViewLoaded.SafeInvoke(this); mvvmBehavior.ViewUnloading += (sender, e) => ViewUnloading.SafeInvoke(this); mvvmBehavior.ViewUnloaded += (sender, e) => ViewUnloaded.SafeInvoke(this); Loaded += (sender, e) => _viewLoaded.SafeInvoke(this, EventArgs.Empty); Unloaded += (sender, e) => _viewUnloaded.SafeInvoke(this, EventArgs.Empty); DataContextChanged += (sender, e) => _viewDataContextChanged.SafeInvoke(this, new DataContextChangedEventArgs(e.OldValue, e.NewValue)); }
/// <summary> /// Initializes a new instance of the <see cref="NestedUserControlsWindow"/> class. /// </summary> public NestedUserControlsWindow() { InitializeComponent(); mvvmBehavior.ViewModelChanged += (sender, e) => ViewModelChanged.SafeInvoke(this, e); mvvmBehavior.ViewModelPropertyChanged += (sender, e) => ViewModelPropertyChanged.SafeInvoke(this, e); mvvmBehavior.ViewLoading += (sender, e) => ViewLoading.SafeInvoke(this); mvvmBehavior.ViewLoaded += (sender, e) => ViewLoaded.SafeInvoke(this); mvvmBehavior.ViewUnloading += (sender, e) => ViewUnloading.SafeInvoke(this); mvvmBehavior.ViewUnloaded += (sender, e) => ViewUnloaded.SafeInvoke(this); Loaded += (sender, e) => _viewLoaded.SafeInvoke(this, EventArgs.Empty); Unloaded += (sender, e) => _viewUnloaded.SafeInvoke(this, EventArgs.Empty); this.SubscribeToDataContext(OnDataContextChanged, true); this.SubscribeToAllDependencyProperties(OnDependencyPropertyChanged); }
internal static void Show_MessageView(string message, Action affirmativeAction = null, string ABtnContent = null, Action negativeAction = null, string BBtnContent = null, FontAwesomeIcon icon = FontAwesomeIcon.None) { Current.Dispatcher.Invoke(() => { ParentView.Current.ProductCatalogBtn.IsEnabled = false; ParentView.Current.DishesCatalogBtn.IsEnabled = false; ParentView.Current.ConfigurationBtn.IsEnabled = false; var oldView = Current.Transition.Content as UserControl; var view = new MessageView(message, affirmativeAction, ABtnContent, negativeAction, BBtnContent, icon); Current.Transition.Content = view; ViewLoaded?.Invoke(view); App.Log.Message($"MessageView, Icon: {icon}, Message: {message}", "VIEW-LOADED"); if (!(oldView is WaitView)) { ViewUnloaded?.Invoke(oldView); } }); }
internal static void Show_MainView() { Current.Dispatcher.Invoke(() => { ParentView.Current.ProductCatalogBtn.IsEnabled = true; ParentView.Current.DishesCatalogBtn.IsEnabled = true; ParentView.Current.ConfigurationBtn.IsEnabled = true; var oldView = Current.Transition.Content as UserControl; var view = new MainView(); Current.Transition.Content = view; ViewLoaded?.Invoke(view); App.Log.Message($"MainView", "VIEW-LOADED"); if (!(oldView is WaitView)) { ViewUnloaded?.Invoke(oldView); } }); }
internal static void Show_AddDishPhoto(Dishes dish) { Current.Dispatcher.Invoke(() => { ParentView.Current.ProductCatalogBtn.IsEnabled = false; ParentView.Current.DishesCatalogBtn.IsEnabled = false; ParentView.Current.ConfigurationBtn.IsEnabled = false; var oldView = Current.Transition.Content as UserControl; var view = new AddDishPhotoView(dish); Current.Transition.Content = view; ViewLoaded?.Invoke(view); App.Log.Message($"AddDishPhotoView. Dish: {dish.ToString()}", "VIEW-LOADED"); if (!(oldView is WaitView)) { ViewUnloaded?.Invoke(oldView); } }); }
internal static void Show_NewProductView(Products product = null) { Current.Dispatcher.Invoke(() => { ParentView.Current.ProductCatalogBtn.IsEnabled = false; ParentView.Current.DishesCatalogBtn.IsEnabled = false; ParentView.Current.ConfigurationBtn.IsEnabled = false; var oldView = Current.Transition.Content as UserControl; var view = new NewProductView(product); Current.Transition.Content = view; ViewLoaded?.Invoke(view); App.Log.Message($"NewProductView, Product: {product.Serialize(LibreR.Models.Enums.Serializer.OneLine)}", "VIEW-LOADED"); if (!(oldView is WaitView)) { ViewUnloaded?.Invoke(oldView); } }); }
private void RaiseViewUnloaded() { ViewUnloaded?.Invoke(this, new ViewStackPartEventArgs(_viewInfo.View)); }
private void OnViewUnloaded(object sender, EventArgs e) { ViewUnloaded.SafeInvoke(this); }
/// <summary> /// Initializes a new instance of the <see cref="PhoneApplicationPage"/> class. /// </summary> /// <remarks> /// It is not possible to inject view models (actually, you can't even /// pass view models during navigation in Windows Phone 7). /// </remarks> public PhoneApplicationPage() { if (Catel.Environment.IsInDesignMode) { return; } var viewModelType = GetViewModelType(); if (viewModelType == null) { Log.Debug("GetViewModelType() returned null, using the ViewModelLocator to resolve the view model"); 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"; Log.Error(error); throw new NotSupportedException(error); } } _logic = new PhoneApplicationPageLogic(this, viewModelType); _logic.TargetControlPropertyChanged += (sender, e) => { OnPropertyChanged(e.FxEventArgs); PropertyChanged.SafeInvoke(this, new PropertyChangedEventArgs(e.PropertyName)); }; _logic.ViewModelChanged += (sender, e) => { OnViewModelChanged(); ViewModelChanged.SafeInvoke(this, e); PropertyChanged.SafeInvoke(this, new PropertyChangedEventArgs("ViewModel")); }; _logic.ViewModelPropertyChanged += (sender, e) => { OnViewModelPropertyChanged(e); ViewModelPropertyChanged.SafeInvoke(this, e); }; _logic.DetermineViewModelInstance += (sender, e) => { e.ViewModel = GetViewModelInstance(e.DataContext); }; _logic.DetermineViewModelType += (sender, e) => { e.ViewModelType = GetViewModelType(e.DataContext); }; _logic.ViewLoading += (sender, e) => ViewLoading.SafeInvoke(this); _logic.ViewLoaded += (sender, e) => ViewLoaded.SafeInvoke(this); _logic.ViewUnloading += (sender, e) => ViewUnloading.SafeInvoke(this); _logic.ViewUnloaded += (sender, e) => ViewUnloaded.SafeInvoke(this); _logic.Tombstoning += (sender, e) => OnTombstoning(); _logic.Tombstoned += (sender, e) => OnTombstoned(); _logic.RecoveringFromTombstoning += (sender, e) => OnRecoveringFromTombstoning(); _logic.RecoveredFromTombstoning += (sender, e) => OnRecoveredFromTombstoning(); ViewModelChanged.SafeInvoke(this); Loaded += (sender, e) => OnLoaded(e); Unloaded += (sender, e) => OnUnloaded(e); }
/// <summary> /// Initializes a new instance of the <see cref="UserControl"/> class. /// </summary> /// <param name="viewModel">The view model.</param> public UserControl(IViewModel viewModel) { if (Catel.Environment.IsInDesignMode) { return; } var viewModelType = (viewModel != null) ? viewModel.GetType() : GetViewModelType(); if (viewModelType == null) { Log.Debug("GetViewModelType() returned null, using the ViewModelLocator to resolve the view model"); 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"; Log.Error(error); throw new NotSupportedException(error); } } _logic = new UserControlLogic(this, viewModelType, viewModel); _logic.TargetControlPropertyChanged += (sender, e) => { #if !NET // WPF already calls this method automatically OnPropertyChanged(e.FxEventArgs); PropertyChanged.SafeInvoke(this, new PropertyChangedEventArgs(e.PropertyName)); #else // 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, "ActualWidth", StringComparison.InvariantCulture) && !string.Equals(e.PropertyName, "ActualHeight", StringComparison.InvariantCulture)) { PropertyChanged.SafeInvoke(this, new PropertyChangedEventArgs(e.PropertyName)); } #endif }; _logic.ViewModelChanged += (sender, e) => { OnViewModelChanged(); ViewModelChanged.SafeInvoke(this, e); PropertyChanged.SafeInvoke(this, new PropertyChangedEventArgs("ViewModel")); }; _logic.ViewModelPropertyChanged += (sender, e) => { OnViewModelPropertyChanged(e); ViewModelPropertyChanged.SafeInvoke(this, e); }; _logic.DetermineViewModelInstance += (sender, e) => { e.ViewModel = GetViewModelInstance(e.DataContext); }; _logic.DetermineViewModelType += (sender, e) => { e.ViewModelType = GetViewModelType(e.DataContext); }; _logic.ViewLoading += (sender, e) => ViewLoading.SafeInvoke(this); _logic.ViewLoaded += (sender, e) => ViewLoaded.SafeInvoke(this); _logic.ViewUnloading += (sender, e) => ViewUnloading.SafeInvoke(this); _logic.ViewUnloaded += (sender, e) => ViewUnloaded.SafeInvoke(this); _logic.ViewModelClosed += OnViewModelClosed; Loaded += (sender, e) => OnLoaded(e); Unloaded += (sender, e) => OnUnloaded(e); }