Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UIViewController"/> class.
        /// </summary>
        public UIViewController()
        {
            if (CatelEnvironment.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 PageLogic(this, viewModelType);
            _logic.TargetViewPropertyChanged += (sender, e) =>
            {
                OnPropertyChanged(e);

                PropertyChanged.SafeInvoke(this, e);
            };

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

            _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);
        }
        /// <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);
        }
Esempio n. 4
0
 private void OnViewUnloading(object sender, EventArgs e)
 {
     ViewUnloading.SafeInvoke(this);
 }
Esempio n. 5
0
        /// <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);
        }
Esempio n. 6
0
        /// <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);
        }