/// <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(); } }
/// <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; }
/// <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; }
/// <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(); } }
/// <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 }
/// <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 }
/// <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; }
/// <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(); }
/// <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); }
/// <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(); }
/// <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(); }
/// <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(); }
/// <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 }
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()); } }
/// <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); } }
/// <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); } }
/// <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; }
/// <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); } }
/// <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); }
/// <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(); }
/// <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); } }
/// <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."); } }
/// <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(); } } }
/// <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) { }
/// <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; }
/// <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); } }
/// <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(); }
/// <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); }
/// <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); }
/// <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) { }
/// <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; } }); }
/// <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) { }
private void OnFrameworkElementUnloaded(object sender, LoadingEventArgs e) { // Not interesting for now... }
/// <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) { }
/// <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(); }