Browse Source

Merge pull request #11828 from robloo/on-loaded-unloaded

Add EventArgs parameter to OnLoaded/Unloaded Methods
pull/11868/head
Max Katz 3 years ago
committed by GitHub
parent
commit
714f88ec55
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      samples/AppWithoutLifetime/MainWindow.axaml.cs
  2. 6
      samples/AppWithoutLifetime/Sub.axaml.cs
  3. 6
      samples/SafeAreaDemo/Views/MainView.xaml.cs
  4. 20
      src/Avalonia.Controls/Control.cs
  5. 6
      src/Avalonia.Controls/ToggleSwitch.cs

5
samples/AppWithoutLifetime/MainWindow.axaml.cs

@ -17,10 +17,11 @@ public partial class MainWindow : Window
AvaloniaXamlLoader.Load(this); AvaloniaXamlLoader.Load(this);
} }
protected override void OnLoaded() /// <inheritdoc/>
protected override void OnLoaded(RoutedEventArgs e)
{ {
this.AttachDevTools(); this.AttachDevTools();
base.OnLoaded(); base.OnLoaded(e);
} }
public void Open(object sender, RoutedEventArgs e) public void Open(object sender, RoutedEventArgs e)

6
samples/AppWithoutLifetime/Sub.axaml.cs

@ -1,5 +1,6 @@
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
namespace AppWithoutLifetime; namespace AppWithoutLifetime;
@ -16,9 +17,10 @@ public partial class Sub : Window
AvaloniaXamlLoader.Load(this); AvaloniaXamlLoader.Load(this);
} }
protected override void OnLoaded() /// <inheritdoc/>
protected override void OnLoaded(RoutedEventArgs e)
{ {
this.AttachDevTools(); this.AttachDevTools();
base.OnLoaded(); base.OnLoaded(e);
} }
} }

6
samples/SafeAreaDemo/Views/MainView.xaml.cs

@ -1,4 +1,5 @@
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
using SafeAreaDemo.ViewModels; using SafeAreaDemo.ViewModels;
@ -11,9 +12,10 @@ namespace SafeAreaDemo.Views
AvaloniaXamlLoader.Load(this); AvaloniaXamlLoader.Load(this);
} }
protected override void OnLoaded() /// <inheritdoc/>
protected override void OnLoaded(RoutedEventArgs e)
{ {
base.OnLoaded(); base.OnLoaded(e);
var insetsManager = TopLevel.GetTopLevel(this)?.InsetsManager; var insetsManager = TopLevel.GetTopLevel(this)?.InsetsManager;
if (insetsManager != null && DataContext is MainViewModel viewModel) if (insetsManager != null && DataContext is MainViewModel viewModel)

20
src/Avalonia.Controls/Control.cs

@ -316,7 +316,8 @@ namespace Avalonia.Controls
((ILogical)this).IsAttachedToLogicalTree) ((ILogical)this).IsAttachedToLogicalTree)
{ {
_isLoaded = true; _isLoaded = true;
OnLoaded();
OnLoaded(new RoutedEventArgs(LoadedEvent, this));
} }
} }
@ -333,28 +334,27 @@ namespace Avalonia.Controls
_loadedQueue.Remove(this); _loadedQueue.Remove(this);
_isLoaded = false; _isLoaded = false;
OnUnloaded();
OnUnloaded(new RoutedEventArgs(UnloadedEvent, this));
} }
} }
/// <summary> /// <summary>
/// Invoked just before the <see cref="Loaded"/> event. /// Invoked just before the <see cref="Loaded"/> event.
/// </summary> /// </summary>
protected virtual void OnLoaded() /// <param name="e">The event args.</param>
protected virtual void OnLoaded(RoutedEventArgs e)
{ {
var eventArgs = new RoutedEventArgs(LoadedEvent); RaiseEvent(e);
eventArgs.Source = null;
RaiseEvent(eventArgs);
} }
/// <summary> /// <summary>
/// Invoked just before the <see cref="Unloaded"/> event. /// Invoked just before the <see cref="Unloaded"/> event.
/// </summary> /// </summary>
protected virtual void OnUnloaded() /// <param name="e">The event args.</param>
protected virtual void OnUnloaded(RoutedEventArgs e)
{ {
var eventArgs = new RoutedEventArgs(UnloadedEvent); RaiseEvent(e);
eventArgs.Source = null;
RaiseEvent(eventArgs);
} }
/// <summary> /// <summary>

6
src/Avalonia.Controls/ToggleSwitch.cs

@ -3,6 +3,7 @@ using Avalonia.Controls.Metadata;
using Avalonia.Controls.Presenters; using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives; using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates; using Avalonia.Controls.Templates;
using Avalonia.Interactivity;
using Avalonia.LogicalTree; using Avalonia.LogicalTree;
namespace Avalonia.Controls namespace Avalonia.Controls
@ -200,9 +201,10 @@ namespace Avalonia.Controls
} }
} }
protected override void OnLoaded() /// <inheritdoc/>
protected override void OnLoaded(RoutedEventArgs e)
{ {
base.OnLoaded(); base.OnLoaded(e);
UpdateKnobTransitions(); UpdateKnobTransitions();
} }

Loading…
Cancel
Save