コード例 #1
0
ファイル: Focus.cs プロジェクト: SOHODeveloper/Catel
 /// <summary>
 /// Called when the <see cref="Behavior{T}.AssociatedObject"/> is loaded.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 protected override void OnAssociatedObjectLoaded(object sender, UIEventArgs e)
 {
     if (!_isFocusAlreadySet && (FocusMoment == FocusMoment.Loaded))
     {
         StartFocus();
     }
 }
コード例 #2
0
        /// <summary>
        /// Called when the <see cref="Behavior{T}.AssociatedObject"/> has been loaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected override void OnAssociatedObjectLoaded(object sender, UIEventArgs e)
        {
            var dependencyProperty = GetDependencyProperty();
            var bindingExpression  = AssociatedObject.GetBindingExpression(dependencyProperty);

            if (bindingExpression == null)
            {
                Log.Error("No binding expression found on '{0}'", UsedDependencyPropertyName);
                return;
            }

            var binding = bindingExpression.ParentBinding;

            _originalBinding = binding;

            var newBinding = CreateBindingCopy(binding);

            newBinding.UpdateSourceTrigger = UpdateSourceTrigger.Explicit;

            AssociatedObject.ClearValue(dependencyProperty);
            AssociatedObject.SetBinding(dependencyProperty, newBinding);

            Log.Debug("Changed UpdateSourceTrigger from to 'Explicit' for dependency property '{0}'", UsedDependencyPropertyName);

            AssociatedObject.SubscribeToDependencyProperty(PropertyName, OnDependencyPropertyChanged);

            Log.Debug("Subscribed to property changes of the original object");

            _timer.Tick += OnTimerTick;
        }
コード例 #3
0
        /// <summary>
        /// Called when the <see cref="Behavior{T}.AssociatedObject"/> is unloaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected override void OnAssociatedObjectUnloaded(object sender, UIEventArgs e)
        {
            _timer.Stop();
            _timer.Tick -= OnTimerTick;

            AssociatedObject.TextChanged -= OnAssociatedObjectTextChanged;
        }
コード例 #4
0
ファイル: LogicBase.cs プロジェクト: SOHODeveloper/Catel
 /// <summary>
 /// Called when the <see cref="TargetControl"/> has just been loaded.
 /// <para />
 /// The base implementation will try to create a view model based on the current DataContext and
 /// set it as the DataContext of the <see cref="TargetControl"/>. To create custom logic for
 /// view model creation, override this method and do not call the base.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 public virtual void OnTargetControlLoaded(object sender, UIEventArgs e)
 {
     if (ViewModel == null)
     {
         ViewModel = CreateViewModelByUsingDataContextOrConstructor();
     }
 }
コード例 #5
0
        /// <summary>
        /// Called when the control is loaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void OnLoaded(object sender, UIEventArgs e)
        {
            Initialize();

#if !NET
            RaiseEventsForAllErrorsAndWarnings();
#endif
        }
コード例 #6
0
        /// <summary>
        /// Called when the <see cref="Behavior{T}.AssociatedObject"/> is unloaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected override void OnAssociatedObjectUnloaded(object sender, UIEventArgs e)
        {
            AssociatedObject.GotFocus -= OnGotFocus;

#if NET
            AssociatedObject.PreviewMouseLeftButtonDown -= OnPreviewMouseLeftButtonDown;
            AssociatedObject.GotMouseCapture            -= OnGotMouseCapture;
            AssociatedObject.GotKeyboardFocus           -= OnGotKeyboardFocus;
#endif
        }
コード例 #7
0
        /// <summary>
        /// Called when the <see cref="LogicBase.TargetControl"/> has just been unloaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public override void OnTargetControlUnloaded(object sender, UIEventArgs e)
        {
            base.OnTargetControlUnloaded(sender, e);

#if NET
            Application.Current.Navigated -= OnNavigatedEvent;
#endif

            ViewModel = null;
        }
コード例 #8
0
        /// <summary>
        /// Called when the <see cref="WindowsListView"/> has been constructed and added to the object tree.
        /// </summary>
        /// <param name="sender">The sender that raised the event.</param>
        /// <param name="e">The event arguments.</param>
        private void OnLoaded(object sender, Xaml.RoutedEventArgs e)
        {
            _scrollViewer = _control.FindFirstElementByType <WindowsScrollViewer>();
            if (_scrollViewer == null)
            {
                return;
            }

            BindScrolledEvent();
        }
コード例 #9
0
        /// <summary>
        /// Called when the <see cref="TriggerAction{T}.AssociatedObject"/> is loaded. This method is introduced to prevent
        /// double initialization when the <see cref="TriggerAction{T}.AssociatedObject"/> is already loaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void OnAssociatedObjectLoadedInternal(object sender, UIEventArgs e)
        {
            if (IsAssociatedObjectLoaded)
            {
                return;
            }

            AssociatedObject.Unloaded += OnAssociatedObjectUnloadedInternal;

            IsAssociatedObjectLoaded = true;

            OnAssociatedObjectLoaded(sender, e);
        }
コード例 #10
0
        /// <summary>
        /// Called when the <see cref="TriggerAction{T}.AssociatedObject"/> is unloaded. This method is introduced to prevent
        /// double uninitialization when the <see cref="TriggerAction{T}.AssociatedObject"/> is already unloaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void OnAssociatedObjectUnloadedInternal(object sender, UIEventArgs e)
        {
            if (!IsAssociatedObjectLoaded)
            {
                return;
            }

            IsAssociatedObjectLoaded = false;

            OnAssociatedObjectUnloaded(sender, e);

            CleanUp();
        }
コード例 #11
0
        /// <summary>
        /// Called when the <see cref="Behavior{T}.AssociatedObject"/> is unloaded. This method is introduced to prevent
        /// double uninitialization when the <see cref="Behavior{T}.AssociatedObject"/> is already unloaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void OnAssociatedObjectUnloadedInternal(object sender, UIEventArgs e)
        {
            _loadCounter--;

            if (_loadCounter != 0)
            {
                return;
            }

            OnAssociatedObjectUnloaded();

            //CleanUp();
        }
コード例 #12
0
        /// <summary>
        /// Called when the <see cref="Behavior{T}.AssociatedObject"/> is loaded. This method is introduced to prevent
        /// double initialization when the <see cref="Behavior{T}.AssociatedObject"/> is already loaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void OnAssociatedObjectLoadedInternal(object sender, UIEventArgs e)
        {
            _loadCounter++;

            // Yes, 1, because we just increased the counter
            if (_loadCounter != 1)
            {
                return;
            }

            AssociatedObject.Unloaded += OnAssociatedObjectUnloadedInternal;

            OnAssociatedObjectLoaded();
        }
コード例 #13
0
        /// <summary>
        /// Called when the control is loaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void OnLoaded(object sender, UIEventArgs e)
        {
            if (_isLoaded)
            {
                return;
            }

            _isLoaded = true;

            Initialize();

#if !NET && !NETCORE
            RaiseEventsForAllErrorsAndWarnings();
#endif
        }
コード例 #14
0
        private void OnFrameworkElementLoaded(object sender, LoadingEventArgs e)
        {
            var elementInfo = (WeakFrameworkElementInfo)sender;

            elementInfo.LayoutUpdated += OnFrameworkElementLayoutUpdated;

            // Loaded is always called first on the inner child, add it to the stack
            lock (_loadedStack)
            {
                _loadedStack.Push(elementInfo);

                var frameworkElement = elementInfo.FrameworkElement;
                frameworkElement.Dispatcher.BeginInvoke(() => frameworkElement.InvalidateMeasure());
            }
        }
コード例 #15
0
        /// <summary>
        /// Called when the framework element is unloaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        public void OnUnloaded(object sender, LoadingEventArgs e)
        {
            if (!IsLoaded)
            {
                return;
            }

            IsLoaded = false;

            var unloaded = Unloaded;

            if (unloaded != null)
            {
                unloaded(this, e);
            }
        }
コード例 #16
0
        /// <summary>
        /// Called when the framework element is loaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        public void OnLoaded(object sender, LoadingEventArgs e)
        {
            if (IsLoaded)
            {
                return;
            }

            IsLoaded = true;

            var loaded = Loaded;

            if (loaded != null)
            {
                loaded(this, e);
            }
        }
コード例 #17
0
        /// <summary>
        /// Called when the <see cref="Behavior{T}.AssociatedObject"/> has been unloaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected override void OnAssociatedObjectUnloaded(object sender, UIEventArgs e)
        {
            var dependencyProperty = GetDependencyProperty();

            AssociatedObject.ClearValue(dependencyProperty);
            AssociatedObject.SetBinding(dependencyProperty, _originalBinding);

            Log.Debug("Restored binding for dependency property '{0}'", UsedDependencyPropertyName);

            AssociatedObject.UnsubscribeFromDependencyProperty(PropertyName, OnDependencyPropertyChanged);

            Log.Debug("Unsubscribed from property changes of the original object");

            _timer.Stop();
            _timer.Tick -= OnTimerTick;
        }
コード例 #18
0
        /// <summary>
        /// Called when the <see cref="TargetControl"/> has just been loaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public override void OnTargetControlLoaded(object sender, UIEventArgs e)
        {
            // Do not call base because it will create a VM. We will create the VM ourselves
            //base.OnTargetControlLoaded(sender, e);

            // Manually updating target control content wrapper here (not by content property changed event handler),
            // because in WinRT UserControl does NOT update bindings while InitializeComponents() method is executing,
            // even if the Content property was changed while InitializeComponents() running there is no triggering of a binding update.
            CreateViewModelGrid();

#if NET || SL4 || SL5
            if (!SkipSearchingForInfoBarMessageControl)
            {
                Log.Debug("Searching for an instance of the InfoBarMessageControl");

                _infoBarMessageControl = FindParentByPredicate(TargetControl, o => o is InfoBarMessageControl) as InfoBarMessageControl;

                Log.Debug("Finished searching for an instance of the InfoBarMessageControl");

                if (_infoBarMessageControl == null)
                {
                    Log.Warning("No InfoBarMessageControl is found in the visual tree of '{0}', consider using the SkipSearchingForInfoBarMessageControl property to improve performance", GetType().Name);
                }
            }
            else
            {
                Log.Debug("Skipping the search for an instance of the InfoBarMessageControl");
            }
#endif

            if (!CloseViewModelOnUnloaded && (ViewModel != null))
            {
                // Re-use view model
                Log.Debug("Re-using existing view model");
            }

            if (ViewModel == null)
            {
                // Try to create view model based on data context
                ViewModel = CreateViewModelByUsingDataContextOrConstructor();
            }

            if (DisableWhenNoViewModel)
            {
                TargetControl.IsEnabled = (ViewModel != null);
            }
        }
コード例 #19
0
ファイル: LogicBase.cs プロジェクト: SOHODeveloper/Catel
        /// <summary>
        /// Called when the <see cref="TargetControl"/> has just been unloaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <remarks>
        /// This method will call the <see cref="OnTargetControlUnloaded"/> which can be overriden for custom
        /// behavior. This method is required to protect from duplicate unloaded events.
        /// </remarks>
        private void OnTargetControlUnloadedInternal(object sender, UIEventArgs e)
        {
            // Don't do this again (another bug in WPF: OnLoaded is called more than OnUnloaded)
            if (!IsTargetControlLoaded)
            {
                return;
            }

            InvokeViewLoadEvent(ViewLoadStateEvent.Unloading);

            IsUnloading = true;

            //#if !NET
            //            _isFirstLayoutUpdatedAfterUnloadedEvent = true;
            //#endif

            Log.Debug("Target control '{0}' is unloaded", TargetControl.GetType().Name);

            var view = TargetControl as IView;

            if (view == null)
            {
                Log.Warning("Cannot unregister view '{0}' in the view manager because it does not implement IView", TargetControl.GetType().FullName);
            }
            else
            {
                _viewManager.UnregisterView(view);
            }

            IsTargetControlLoaded         = false;
            _isFirstValidationAfterLoaded = true;

            OnTargetControlUnloaded(sender, e);

            var targetControlAsIViewModelContainer = TargetControl as IViewModelContainer;

            if (targetControlAsIViewModelContainer != null)
            {
                ViewToViewModelMappingHelper.UninitializeViewToViewModelMappings(targetControlAsIViewModelContainer);
            }

            IsUnloading = false;

            InvokeViewLoadEvent(ViewLoadStateEvent.Unloaded);
        }
コード例 #20
0
        /// <summary>
        /// Called when the <see cref="TriggerAction{T}.AssociatedObject"/> is loaded. This method is introduced to prevent
        /// double initialization when the <see cref="TriggerAction{T}.AssociatedObject"/> is already loaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void OnAssociatedObjectLoadedInternal(object sender, UIEventArgs e)
        {
            _loadCounter++;

            // Yes, 1, because we just increased the counter
            if (_loadCounter != 1)
            {
                return;
            }

            if (!_isSubscribedToUnloadedEvent)
            {
                AssociatedObject.Unloaded   += OnAssociatedObjectUnloadedInternal;
                _isSubscribedToUnloadedEvent = true;
            }

            OnAssociatedObjectLoaded();
        }
コード例 #21
0
        /// <summary>
        /// Called when the <see cref="TargetControl"/> has just been loaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public override void OnTargetControlLoaded(object sender, UIEventArgs e)
        {
            // Do not call base because it will create a VM. We will create the VM ourselves
            //base.OnTargetControlLoaded(sender, e);

#if NET || SL4 || SL5
            if (!SkipSearchingForInfoBarMessageControl)
            {
                Log.Debug("Searching for an instance of the InfoBarMessageControl");

                _infoBarMessageControl = FindParentByPredicate(TargetControl, o => o is InfoBarMessageControl) as InfoBarMessageControl;

                Log.Debug("Finished searching for an instance of the InfoBarMessageControl");

                if (_infoBarMessageControl == null)
                {
                    Log.Warning("No InfoBarMessageControl is found in the visual tree of '{0}', consider using the SkipSearchingForInfoBarMessageControl property to improve performance", GetType().Name);
                }
            }
            else
            {
                Log.Debug("Skipping the search for an instance of the InfoBarMessageControl");
            }
#endif

            if (!CloseViewModelOnUnloaded && (ViewModel != null))
            {
                // Re-use view model
                Log.Debug("Re-using existing view model");
            }

            if (ViewModel == null)
            {
                // Try to create view model based on data context
                ViewModel = CreateViewModelByUsingDataContextOrConstructor();
            }

            if (DisableWhenNoViewModel)
            {
                TargetControl.IsEnabled = (ViewModel != null);
            }
        }
コード例 #22
0
        /// <summary>
        /// Called when the <see cref="TargetControl"/> has just been unloaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public override void OnTargetControlUnloaded(object sender, UIEventArgs e)
        {
            base.OnTargetControlUnloaded(sender, e);

            if (ViewModel != null)
            {
                ClearWarningsAndErrorsForObject(ViewModel);
            }

            UnsubscribeFromParentViewModelContainer();

            if (CloseViewModelOnUnloaded)
            {
                CloseAndDisposeViewModel(true);
            }
            else
            {
                Log.Debug("Skipping 'CloseAndDisposeViewModel' because 'CloseViewModelOnUnloaded' is set to false.");
            }
        }
コード例 #23
0
ファイル: Authentication.cs プロジェクト: SOHODeveloper/Catel
        /// <summary>
        /// Called when the <see cref="Behavior{T}.AssociatedObject"/> has been loaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <exception cref="InvalidOperationException">No instance of <see cref="IAuthenticationProvider"/> is registered in the <see cref="IServiceLocator"/>.</exception>
        /// <exception cref="InvalidOperationException">The <see cref="Action"/> is set to <see cref="AuthenticationAction.Disable"/> and the <see cref="Behavior{T}.AssociatedObject"/> is not a <see cref="Control"/>.</exception>
        protected override void OnAssociatedObjectLoaded(object sender, UIEventArgs e)
        {
            if (!_authenticationProvider.HasAccessToUIElement(AssociatedObject, AssociatedObject.Tag, AuthenticationTag))
            {
                Log.Debug("User has no access to UI element with tag '{0}' and authentication tag '{1}'",
                          ObjectToStringHelper.ToString(AssociatedObject.Tag), ObjectToStringHelper.ToString(AuthenticationTag));

                switch (Action)
                {
#if NET
                case AuthenticationAction.Hide:
                    AssociatedObject.Visibility = Visibility.Hidden;
                    break;
#endif

                case AuthenticationAction.Collapse:
                    AssociatedObject.Visibility = Visibility.Collapsed;
                    break;

                case AuthenticationAction.Disable:
#if SILVERLIGHT || NETFX_CORE
                    if (!(AssociatedObject is Control))
                    {
                        throw new InvalidOperationException("The AssociatedObject is not a Control instance, only AuthenticationAction.Collapse is allowed in SL, Windows Phone and WinRT");
                    }

                    ((Control)AssociatedObject).IsEnabled = false;
#else
                    AssociatedObject.IsEnabled = false;
#endif
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
コード例 #24
0
ファイル: UserControlLogic.cs プロジェクト: JaysonJG/Catel
        /// <summary>
        /// Called when the <see cref="TargetControl"/> has just been unloaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public override void OnTargetControlUnloaded(object sender, UIEventArgs e)
        {
            base.OnTargetControlUnloaded(sender, e);

            if (ViewModel != null)
            {
                ClearWarningsAndErrorsForObject(ViewModel);
            }

            UnsubscribeFromParentViewModelContainer();

            if (CloseViewModelOnUnloaded)
            {
                CloseAndDisposeViewModel(true);
            }
            else
            {
                Log.Debug("Skipping 'CloseAndDisposeViewModel' because 'CloseViewModelOnUnloaded' is set to false.");
            }
        }
コード例 #25
0
ファイル: UserControlLogic.cs プロジェクト: JaysonJG/Catel
        /// <summary>
        /// Called when the <see cref="TargetControl"/> has just been loaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public override void OnTargetControlLoaded(object sender, UIEventArgs e)
        {
            // Do not call base because it will create a VM. We will create the VM ourselves
            //base.OnTargetControlLoaded(sender, e);

            // Manually updating target control content wrapper here (not by content property changed event handler),
            // because in WinRT UserControl does NOT update bindings while InitializeComponents() method is executing,
            // even if the Content property was changed while InitializeComponents() running there is no triggering of a binding update.
            CreateViewModelGrid();

#if NET || SL4 || SL5
            if (!SkipSearchingForInfoBarMessageControl)
            {
                Log.Debug("Searching for an instance of the InfoBarMessageControl");

                _infoBarMessageControl = FindParentByPredicate(TargetControl, o => o is InfoBarMessageControl) as InfoBarMessageControl;

                Log.Debug("Finished searching for an instance of the InfoBarMessageControl");

                if (_infoBarMessageControl == null)
                {
                    Log.Warning("No InfoBarMessageControl is found in the visual tree of '{0}', consider using the SkipSearchingForInfoBarMessageControl property to improve performance", GetType().Name);
                }
            }
            else
            {
                Log.Debug("Skipping the search for an instance of the InfoBarMessageControl");
            }
#endif

            if (!CloseViewModelOnUnloaded && (ViewModel != null))
            {
                // Re-use view model
                Log.Debug("Re-using existing view model");
            }

            if (ViewModel == null)
            {
                // Try to create view model based on data context
                ViewModel = CreateViewModelByUsingDataContextOrConstructor();
            }

            if (DisableWhenNoViewModel)
            {
                TargetControl.IsEnabled = (ViewModel != null);
            }
        }
コード例 #26
0
ファイル: UserControlLogic.cs プロジェクト: pars87/Catel
        /// <summary>
        /// Called when the <see cref="TargetControl"/> has just been loaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public override void OnTargetControlLoaded(object sender, UIEventArgs e)
        {
            // Do not call base because it will create a VM. We will create the VM ourselves
            //base.OnTargetControlLoaded(sender, e);

#if NET || SL4 || SL5
            if (!SkipSearchingForInfoBarMessageControl)
            {
                Log.Debug("Searching for an instance of the InfoBarMessageControl");

                _infoBarMessageControl = FindParentByPredicate(TargetControl, o => o is InfoBarMessageControl) as InfoBarMessageControl;

                Log.Debug("Finished searching for an instance of the InfoBarMessageControl");

                if (_infoBarMessageControl == null)
                {
                    Log.Warning("No InfoBarMessageControl is found in the visual tree of '{0}', consider using the SkipSearchingForInfoBarMessageControl property to improve performance", GetType().Name);
                }
            }
            else
            {
                Log.Debug("Skipping the search for an instance of the InfoBarMessageControl");
            }
#endif

            if (!CloseViewModelOnUnloaded && (ViewModel != null))
            {
                // Re-use view model
                Log.Debug("Re-using existing view model");
            }

            if (ViewModel == null)
            {
                // Try to create view model based on data context
                ViewModel = CreateViewModelByUsingDataContextOrConstructor();
            }

            if (DisableWhenNoViewModel)
            {
                TargetControl.IsEnabled = (ViewModel != null);
            }
        }
コード例 #27
0
ファイル: Page.cs プロジェクト: szogun1987/Catel
 /// <summary>
 /// Called when the page is unloaded.
 /// </summary>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 protected virtual void OnUnloaded(UIEventArgs e)
 {
 }
コード例 #28
0
        /// <summary>
        /// Called when the framework element is loaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        public void OnLoaded(object sender, LoadingEventArgs e)
        {
            if (IsLoaded)
            {
                return;
            }

            IsLoaded = true;

            var loaded = Loaded;
            if (loaded != null)
            {
                loaded(this, e);
            }
        }
コード例 #29
0
        /// <summary>
        /// Called when the framework element is unloaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        public void OnUnloaded(object sender, LoadingEventArgs e)
        {
            if (!IsLoaded)
            {
                return;
            }

            IsLoaded = false;

            var unloaded = Unloaded;
            if (unloaded != null)
            {
                unloaded(this, e);
            }
        }
コード例 #30
0
ファイル: MouseInfo.cs プロジェクト: SOHODeveloper/Catel
 /// <summary>
 /// Called when the <see cref="System.Windows.Interactivity.TriggerBase{T}.AssociatedObject"/> is unloaded.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 protected override void OnAssociatedObjectUnloaded(object sender, UIEventArgs e)
 {
     AssociatedObject.MouseEnter -= OnMouseEnter;
     AssociatedObject.MouseLeave -= OnMouseLeave;
 }
コード例 #31
0
ファイル: LogicBase.cs プロジェクト: pars87/Catel
 /// <summary>
 /// Called when the <see cref="TargetControl"/> has just been loaded.
 /// <para />
 /// The base implementation will try to create a view model based on the current DataContext and
 /// set it as the DataContext of the <see cref="TargetControl"/>. To create custom logic for
 /// view model creation, override this method and do not call the base.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 public virtual void OnTargetControlLoaded(object sender, UIEventArgs e)
 {
     if (ViewModel == null)
     {
         ViewModel = CreateViewModelByUsingDataContextOrConstructor();
     }
 }
コード例 #32
0
ファイル: LogicBase.cs プロジェクト: pars87/Catel
        /// <summary>
        /// Called when the <see cref="TargetControl"/> has just been unloaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <remarks>
        /// This method will call the <see cref="OnTargetControlUnloaded"/> which can be overriden for custom 
        /// behavior. This method is required to protect from duplicate unloaded events.
        /// </remarks>
        private void OnTargetControlUnloadedInternal(object sender, UIEventArgs e)
        {
            // Don't do this again (another bug in WPF: OnLoaded is called more than OnUnloaded)
            if (!IsTargetControlLoaded)
            {
                return;
            }

//#if !NET
//            _isFirstLayoutUpdatedAfterUnloadedEvent = true;
//#endif

            Log.Debug("Target control '{0}' is unloaded", TargetControl.GetType().Name);

            var view = TargetControl as IView;
            if (view == null)
            {
                Log.Warning("Cannot unregister view '{0}' in the view manager because it does not implement IView", TargetControl.GetType().FullName);
            }
            else
            {
                _viewManager.UnregisterView(view);
            }

            IsTargetControlLoaded = false;
            _isFirstValidationAfterLoaded = true;

            OnTargetControlUnloaded(sender, e);

            var targetControlAsIViewModelContainer = TargetControl as IViewModelContainer;
            if (targetControlAsIViewModelContainer != null)
            {
                ViewToViewModelMappingHelper.UninitializeViewToViewModelMappings(targetControlAsIViewModelContainer);
            }
        }
コード例 #33
0
ファイル: BehaviorBase.cs プロジェクト: lixingx86/Catel
 /// <summary>
 /// Called when the <see cref="Behavior{T}.AssociatedObject"/> is unloaded. This method is introduced to prevent
 /// double uninitialization when the <see cref="Behavior{T}.AssociatedObject"/> is already unloaded.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 private void OnAssociatedObjectUnloadedInternal(object sender, UIEventArgs e)
 {
     OnAssociatedObjectUnloadedInternal();
 }
コード例 #34
0
        /// <summary>
        /// Called when the <see cref="LogicBase.TargetControl"/> has just been loaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public override void OnTargetControlLoaded(object sender, UIEventArgs e)
        {
            base.OnTargetControlLoaded(sender, e);

            InitializeNavigationService(true);
        }
コード例 #35
0
        /// <summary>
        /// Called when the associated object is unloaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected override void OnAssociatedObjectUnloaded(object sender, UIEventArgs e)
        {
            UnsubscribeFromCommand();

            base.OnAssociatedObjectUnloaded(sender, e);
        }
コード例 #36
0
ファイル: LogicBase.cs プロジェクト: pars87/Catel
 /// <summary>
 /// Called when the <see cref="TargetControl"/> has just been unloaded.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 public virtual void OnTargetControlUnloaded(object sender, UIEventArgs e)
 {
 }
コード例 #37
0
        private void OnFrameworkElementLoaded(object sender, LoadingEventArgs e)
        {
            var elementInfo = (WeakFrameworkElementInfo)sender;
            elementInfo.LayoutUpdated += OnFrameworkElementLayoutUpdated;

            // Loaded is always called first on the inner child, add it to the stack
            lock (_loadedStack)
            {
                _loadedStack.Push(elementInfo);

                var frameworkElement = elementInfo.FrameworkElement;
                frameworkElement.Dispatcher.BeginInvoke(() => frameworkElement.InvalidateMeasure());
            }
        }
コード例 #38
0
ファイル: LogicBase.cs プロジェクト: pars87/Catel
        /// <summary>
        /// Called when the <see cref="TargetControl"/> has just been loaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <remarks>
        /// This method will call the <see cref="OnTargetControlLoaded"/> which can be overriden for custom 
        /// behavior. This method is required to protect from duplicate loaded events.
        /// </remarks>
        private void OnTargetControlLoadedInternal(object sender, UIEventArgs e)
        {
            // Don't do this again (another bug in WPF: OnLoaded is called more than OnUnloaded)
            if (IsTargetControlLoaded)
            {
                return;
            }

            if (!CanControlBeLoaded)
            {
                Log.Debug("Received Loaded or LayoutUpdated, but CanControlBeLoaded is false thus not treating the control as loaded");
                return;
            }

            Log.Debug("Target control '{0}' is loaded", TargetControl.GetType().Name);

            var view = TargetControl as IView;
            if (view == null)
            {
                Log.Warning("Cannot register view '{0}' in the view manager because it does not implement IView", TargetControl.GetType().FullName);
            }
            else
            {
                _viewManager.RegisterView(view);
            }

            IsTargetControlLoaded = true;

            OnTargetControlLoaded(sender, e);

#if !NET
            // According to the documentation, no visual tree is garantueed in the Loaded event of the user control.
            // However, as a solution the documentation says you need to manually call ApplyTemplate, so let's do that.
            // For more info, see http://msdn.microsoft.com/en-us/library/ms596558(vs.95)
            var targetControl = TargetControl as Control;
            if (targetControl != null)
            {
                (targetControl).ApplyTemplate();
            }
#endif

            var targetControlAsIViewModelContainer = TargetControl as IViewModelContainer;
            if (targetControlAsIViewModelContainer != null)
            {
                ViewToViewModelMappingHelper.InitializeViewToViewModelMappings(targetControlAsIViewModelContainer);
            }

            var dispatcher = TargetControl.Dispatcher;
            dispatcher.BeginInvokeIfRequired(() =>
            {
                if (ViewModel != null)
                {
                    // Initialize the view model. The view model itself is responsible to prevent double initialization
                    ViewModel.InitializeViewModel();

                    // Revalidate since the control already initialized the view model before the control
                    // was visible, therefore the WPF engine does not show warnings and errors
                    var viewModelAsViewModelBase = ViewModel as ViewModelBase;
                    if (viewModelAsViewModelBase != null)
                    {
                        viewModelAsViewModelBase.Validate(true, false);
                    }
                    else
                    {
                        ViewModel.ValidateViewModel(true, false);
                    }

                    _isFirstValidationAfterLoaded = true;
                }
            });
        }
コード例 #39
0
 /// <summary>
 /// Called when the <see cref="TriggerAction{T}.AssociatedObject"/> is unloaded.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 protected virtual void OnAssociatedObjectUnloaded(object sender, UIEventArgs e)
 {
 }
コード例 #40
0
 private void OnFrameworkElementUnloaded(object sender, LoadingEventArgs e)
 {
     // Not interesting for now...
 }
コード例 #41
0
ファイル: UserControl.cs プロジェクト: matthijskoopman/Catel
 /// <summary>
 /// Called when the user control is unloaded.
 /// </summary>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 protected virtual void OnUnloaded(UIEventArgs e)
 {
 }
コード例 #42
0
        /// <summary>
        /// Called when the control is loaded.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void OnLoaded(object sender, UIEventArgs e)
        {
            Initialize();

#if !NET
            RaiseEventsForAllErrorsAndWarnings();
#endif
        }
コード例 #43
0
 /// <summary>
 /// Called when the control is unloaded.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 private void OnUnloaded(object sender, UIEventArgs e)
 {
     CleanUp();
 }
コード例 #44
0
 /// <summary>
 /// Called when the control is unloaded.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 private void OnUnloaded(object sender, UIEventArgs e)
 {
     CleanUp();
 }