コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainWindow"/> class.
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            InitializeMainWindow();

            _windowLogic = new WindowLogic(this, typeof(MainWindowViewModel));
            _windowLogic.ViewModelChanged += (s, e) =>
            {
                ViewModelChanged.SafeInvoke(this, e);
                PropertyChanged.SafeInvoke(this, new PropertyChangedEventArgs("ViewModel"));
            };
            _windowLogic.ViewModelPropertyChanged += (s, e) => ViewModelPropertyChanged.SafeInvoke(this, e);

            // _windowLogic.TargetControlPropertyChanged += (s, e) => PropertyChanged.SafeInvoke(this, new AdvancedPropertyChangedEventArgs(s, this, e.PropertyName, e.OldValue, e.NewValue));
            var serviceLocator = ServiceLocator.Default;

            serviceLocator.RegisterInstance(this);
            serviceLocator.RegisterInstance(ribbon);
            serviceLocator.RegisterInstance(dockingManager);
            serviceLocator.RegisterInstance(layoutDocumentPane);

            ribbon.AutomaticStateManagement = true;
            ribbon.EnsureTabItem("Home");

            Loaded += (sender, e) => { traceOutputAnchorable.Hide(); };
        }
コード例 #2
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"));
        }
コード例 #3
0
        public NestedUserControlsWindow()
        {
            InitializeComponent();

            mvvmBehavior.ViewModelChanged         += (sender, e) => ViewModelChanged.SafeInvoke(this, e);
            mvvmBehavior.ViewModelPropertyChanged += (sender, e) => ViewModelPropertyChanged.SafeInvoke(this, e);
        }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RoomView"/> class.
        /// </summary>
        public RoomView()
        {
            InitializeComponent();

            mvvmBehavior.ViewModelChanged         += (sender, e) => ViewModelChanged.SafeInvoke(this, e);
            mvvmBehavior.ViewModelPropertyChanged += (sender, e) => ViewModelPropertyChanged.SafeInvoke(this, e);
        }
コード例 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleDataWindow" /> class.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        /// <param name="mode">The data window mode.</param>
        /// <param name="additionalButtons">The additional buttons.</param>
        /// <exception cref="System.NotSupportedException"></exception>
        protected SimpleDataWindow(IViewModel viewModel, DataWindowMode mode = DataWindowMode.OkCancel, IEnumerable <DataWindowButton> additionalButtons = null)
        {
            if (CatelEnvironment.IsInDesignMode)
            {
                return;
            }

            ThemeHelper.EnsureCatelMvvmThemeIsLoaded();

            _logic = new WindowLogic(this, null, viewModel);
            _logic.PropertyChanged          += (sender, e) => PropertyChanged.SafeInvoke(this, e);
            _logic.ViewModelChanged         += (sender, e) => ViewModelChanged.SafeInvoke(this, e);
            _logic.ViewModelPropertyChanged += (sender, e) => ViewModelPropertyChanged.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));

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

            var languageService = ServiceLocator.Default.ResolveType <ILanguageService>();

            if (mode == DataWindowMode.OkCancel || mode == DataWindowMode.OkCancelApply)
            {
                var button = DataWindowButton.FromAsync(languageService.GetString("OK"), OnOkExecuteAsync, OnOkCanExecute);
                button.IsDefault = true;
                _buttons.Add(button);
            }

            if (mode == DataWindowMode.OkCancel || mode == DataWindowMode.OkCancelApply)
            {
                var button = DataWindowButton.FromAsync(languageService.GetString("Cancel"), OnCancelExecuteAsync, OnCancelCanExecute);
                button.IsCancel = true;
                _buttons.Add(button);
            }

            if (mode == DataWindowMode.OkCancelApply)
            {
                var button = DataWindowButton.FromSync(languageService.GetString("Apply"), OnApplyExecute, OnApplyCanExecute);
                _buttons.Add(button);
            }

            if (mode == DataWindowMode.Close)
            {
                var button = DataWindowButton.FromSync(languageService.GetString("Close"), OnCloseExecute, null);
                _buttons.Add(button);
            }

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

            this.FixBlurriness();
        }
コード例 #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DemoWindow"/> class.
        /// </summary>
        public DemoWindow()
        {
            InitializeComponent();

            mvvmBehavior.ViewModelChanged             += (sender, e) => ViewModelChanged.SafeInvoke(this, e);
            mvvmBehavior.ViewModelPropertyChanged     += (sender, e) => ViewModelPropertyChanged.SafeInvoke(this, e);
            mvvmBehavior.TargetControlPropertyChanged += (sender, e) => PropertyChanged.SafeInvoke(this, new PropertyChangedEventArgs(e.PropertyName));
        }
コード例 #7
0
ファイル: UserControl.cs プロジェクト: szogun1987/Catel
        /// <summary>
        /// Initializes a new instance of the <see cref="UserControl"/> class.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        public UserControl(IViewModel viewModel)
        {
            if (CatelEnvironment.IsInDesignMode)
            {
                return;
            }

            this.FixBlurriness();

            _logic = new UserControlLogic(this, null, viewModel);

            _logic.TargetViewPropertyChanged += (sender, e) =>
            {
#if !NET
                // WPF already calls this method automatically
                OnPropertyChanged(e);

                PropertyChanged.SafeInvoke(this, e);
#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, e);
                }
#endif
            };

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

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

                ViewModelPropertyChanged.SafeInvoke(this, e);
            };

            Loaded += (sender, e) =>
            {
                _viewLoaded.SafeInvoke(this);

                OnLoaded(e);
            };

            Unloaded += (sender, e) =>
            {
                _viewUnloaded.SafeInvoke(this);

                OnUnloaded(e);
            };

            this.AddDataContextChangedHandler((sender, e) => _viewDataContextChanged.SafeInvoke(this, new Catel.MVVM.Views.DataContextChangedEventArgs(e.OldValue, e.NewValue)));
        }
コード例 #8
0
ファイル: UIViewController.cs プロジェクト: yicong/Catel
        /// <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);
        }
コード例 #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleDataWindow" /> class.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        /// <param name="mode">The data window mode.</param>
        /// <param name="additionalButtons">The additional buttons.</param>
        /// <exception cref="System.NotSupportedException"></exception>
        protected SimpleDataWindow(IViewModel viewModel, DataWindowMode mode = DataWindowMode.OkCancel, IEnumerable <DataWindowButton> additionalButtons = null)
        {
            _logic = new WindowLogic(this, null, viewModel);
            _logic.PropertyChanged          += (sender, e) => PropertyChanged.SafeInvoke(this, e);
            _logic.ViewModelChanged         += (sender, e) => ViewModelChanged.SafeInvoke(this, e);
            _logic.ViewModelPropertyChanged += (sender, e) => ViewModelPropertyChanged.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));

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

            if (mode == DataWindowMode.OkCancel || mode == DataWindowMode.OkCancelApply)
            {
                var button = new DataWindowButton("Ok", async() => await OnOkExecuteAsync(), OnOkCanExecute);
                button.IsDefault = true;
                _buttons.Add(button);
            }

            if (mode == DataWindowMode.OkCancel || mode == DataWindowMode.OkCancelApply)
            {
                var button = new DataWindowButton("Cancel", async() => await OnCancelExecuteAsync(), OnCancelCanExecute);
                button.IsCancel = true;
                _buttons.Add(button);
            }

            if (mode == DataWindowMode.OkCancelApply)
            {
                var button = new DataWindowButton("Apply", OnApplyExcute, OnApplyCanExecute);
                _buttons.Add(button);
            }

            if (mode == DataWindowMode.Close)
            {
                var button = new DataWindowButton("Close", OnCloseExecute);
                _buttons.Add(button);
            }

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

            this.FixBlurriness();
        }
コード例 #10
0
        /// <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));
        }
コード例 #11
0
        /// <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);
        }
コード例 #12
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 (CatelEnvironment.IsInDesignMode)
            {
                return;
            }

            _logic = new PageLogic(this);
            _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);
            };

            Loaded += (sender, e) =>
            {
                _viewLoaded.SafeInvoke(this);

                OnLoaded(e);
            };

            Unloaded += (sender, e) =>
            {
                _viewUnloaded.SafeInvoke(this);

                OnUnloaded(e);
            };

            this.AddDataContextChangedHandler((sender, e) => _viewDataContextChanged.SafeInvoke(this, new DataContextChangedEventArgs(e.OldValue, e.NewValue)));
        }
コード例 #13
0
ファイル: ContentPage.cs プロジェクト: shekky/Catel
        /// <summary>
        ///     Initializes a new instance of the <see cref="ContentPage" /> class.
        /// </summary>
        /// <param name="viewModel">The view model</param>
        public ContentPage(IViewModel viewModel)
        {
            _userControlLogic = new UserControlLogic(this, null, viewModel);

            _userControlLogic.TargetViewPropertyChanged += (sender, e) =>
            {
                OnPropertyChanged(e.PropertyName);
            };

            _userControlLogic.ViewModelClosedAsync += OnViewModelClosedAsync;

            _userControlLogic.ViewModelChanged += (sender, args) =>
            {
                if (!ObjectHelper.AreEqual(BindingContext, _userControlLogic.ViewModel))
                {
                    BindingContext = _userControlLogic.ViewModel;
                }
            };

            _userControlLogic.ViewModelPropertyChanged += (sender, e) =>
            {
                OnViewModelPropertyChanged(e);
                ViewModelPropertyChanged.SafeInvoke(this, e);
            };

            Loaded += (sender, e) =>
            {
                // _viewLoaded.SafeInvoke(this);
                // OnLoaded(e);
            };

            Unloaded += (sender, e) =>
            {
                // _viewUnloaded.SafeInvoke(this);
                // OnUnloaded(e);
            };

            DataContextChanged += OnDataContextChanged;
        }
コード例 #14
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MetroDataWindow"/> class.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        protected MetroDataWindow(IViewModel viewModel)
        {
            _logic = new WindowLogic(this, null, 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();

            WindowStartupLocation = WindowStartupLocation.CenterScreen;

            this.FixBlurriness();
            this.ApplyIconFromApplication();
        }
コード例 #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Fragment" /> class.
        /// </summary>
        /// <exception cref="System.NotSupportedException"></exception>
        public Fragment()
        {
            if (CatelEnvironment.IsInDesignMode)
            {
                return;
            }

            _logic = new UserControlLogic(this, null);
            _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);
            };
        }
コード例 #16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Activity"/> class.
        /// </summary>
        public Activity()
        {
            if (CatelEnvironment.IsInDesignMode)
            {
                return;
            }

            _logic = new PageLogic(this);
            _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);
            };
        }
コード例 #17
0
ファイル: DataWindow.cs プロジェクト: thincster/Catel
        /// <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, "ActualWidth", StringComparison.InvariantCulture) &&
                    !string.Equals(e.PropertyName, "ActualHeight", StringComparison.InvariantCulture))
                {
                    PropertyChanged.SafeInvoke(this, e);
                }
            };

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

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

                ViewModelPropertyChanged.SafeInvoke(this, e);
            };

            Loaded += (sender, e) =>
            {
                _viewLoaded.SafeInvoke(this);

                OnLoaded(e);
            };

            Unloaded += (sender, e) =>
            {
                _viewUnloaded.SafeInvoke(this);

                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.SafeInvoke(this, () => new DataContextChangedEventArgs(e.OldValue, e.NewValue));

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

            if (setOwnerAndFocus)
            {
                this.SetOwnerWindowAndFocus(focusFirstControl: focusFirstControl);
            }
            else if (focusFirstControl)
            {
                this.FocusFirstControl();
            }
        }
コード例 #18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Page"/> class.
        /// </summary>
        /// <remarks>
        /// It is not possible to inject view models.
        /// </remarks>
        public Page()
        {
            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 NavigationPageLogic(this, viewModelType);
            _logic.TargetControlPropertyChanged += (sender, e) =>
            {
#if !NET
                // WPF already calls this method automatically
                OnPropertyChanged(e.FxEventArgs);

                // Do not call this for WPF, will cause problems with ActualWidth and ActualHeight
                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);
            };

            ViewModelChanged.SafeInvoke(this);

            Loaded   += (sender, e) => OnLoaded(e);
            Unloaded += (sender, e) => OnUnloaded(e);
        }
コード例 #19
0
ファイル: UserControl.cs プロジェクト: SOHODeveloper/Catel
        /// <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);
        }
コード例 #20
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);
        }
コード例 #21
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>
        public MetroDataWindow(IViewModel viewModel, DataWindowMode mode, IEnumerable <DataWindowButton> additionalButtons = null,
                               DataWindowDefaultButton defaultButton = DataWindowDefaultButton.OK, bool setOwnerAndFocus = true,
                               InfoBarMessageControlGenerationMode infoBarMessageControlGenerationMode = InfoBarMessageControlGenerationMode.Inline)
        {
            if (CatelEnvironment.IsInDesignMode)
            {
                return;
            }

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

            this.FixBlurriness();

            SizeToContent         = SizeToContent.WidthAndHeight;
            ShowInTaskbar         = false;
            ResizeMode            = ResizeMode.NoResize;
            WindowStartupLocation = WindowStartupLocation.CenterOwner;
            BorderThickness       = new Thickness(1d);
            BorderBrush           = Orchestra.ThemeHelper.GetAccentColorBrush();

            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, "ActualWidth", StringComparison.InvariantCulture) &&
                    !string.Equals(e.PropertyName, "ActualHeight", StringComparison.InvariantCulture))
                {
                    PropertyChanged.SafeInvoke(this, e);
                }
            };

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

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

                ViewModelPropertyChanged.SafeInvoke(this, e);
            };

            Loaded += (sender, e) =>
            {
                _viewLoaded.SafeInvoke(this);

                OnLoaded(e);
            };

            Unloaded += (sender, e) =>
            {
                _viewUnloaded.SafeInvoke(this);

                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();
            Closing            += OnDataWindowClosing;
            DataContextChanged += (sender, e) => _viewDataContextChanged.SafeInvoke(this, new DataContextChangedEventArgs(e.OldValue, e.NewValue));

            if (setOwnerAndFocus)
            {
                this.SetOwnerWindowAndFocus();
            }
            else
            {
                this.FocusFirstControl();
            }
        }
コード例 #22
0
 /// <summary>
 /// Called when a property on the <see cref="ViewModel"/> has changed.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="System.ComponentModel.PropertyChangedEventArgs"/> instance containing the event data.</param>
 public virtual void OnViewModelPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     ViewModelPropertyChanged.SafeInvoke(this, e);
 }
コード例 #23
0
 /// <summary>
 /// Called when a property on the <see cref="LogicBase.ViewModel"/> has changed.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 private void OnLogicViewModelPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     ViewModelPropertyChanged.SafeInvoke(this, e);
 }
コード例 #24
0
        public ShellViewBase(IViewModel viewModel)
        {
            if (AppEnvironment.IsInDesignMode)
            {
                return;
            }
            //IRegionManager regionManager =Microsoft.Practices.ServiceLocation.ServiceLocator.Current.GetInstance<IRegionManager>();
            //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);
            //    }
            //}
            var serviceLocator = ServiceLocator.Default;

            serviceLocator.RegisterInstance <ShellViewBase>(this);
            _windowLogic = new WindowLogic(this, null, viewModel);
            _windowLogic.ViewModelPropertyChanged += (s, 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, "ActualWidth", StringComparison.InvariantCulture) &&
                    !string.Equals(e.PropertyName, "ActualHeight", StringComparison.InvariantCulture))
                {
                    PropertyChanged.SafeInvoke(this, e);
                }
            };
            _windowLogic.ViewModelClosed          += OnViewModelClosed;
            _windowLogic.ViewModelChanged         += (sender, e) => RaiseViewModelChanged();
            _windowLogic.ViewModelPropertyChanged += (sender, e) =>
            {
                OnViewModelPropertyChanged(sender, e);
                ViewModelPropertyChanged.SafeInvoke(this, e);
            };

            Loaded += (sender, e) =>
            {
                _viewLoaded.SafeInvoke(this);
                //OnLoaded(e);
            };

            Unloaded += (sender, e) =>
            {
                _viewUnloaded.SafeInvoke(this);
                //OnUnloaded(e);
            };
            SetBinding(TitleProperty, new Binding("Title"));
            Loaded             += (sender, e) => Initialize();
            Closing            += OnDataWindowClosing;
            DataContextChanged += (sender, e) => _viewDataContextChanged.SafeInvoke(this, new DataContextChangedEventArgs(e.OldValue, e.NewValue));

            //eventAggregator = (IEventAggregator)serviceLocator.GetService(typeof(IEventAggregator));



            //Loaded += (sender, e) =>
            //{
            //    string inputFilePathName = GloableStaticInstanse.StartupInputFilePathName;
            //    if (!string.IsNullOrEmpty(inputFilePathName))
            //    {
            //        System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => ((MetaShellViewModel)ViewModel).PackageService.Open(inputFilePathName)));

            //    }
            //};
        }