diff --git a/Toolkit.Avalonia/ContentControlHandler.cs b/Toolkit.Avalonia/ContentControlHandler.cs
index c12ad16..5cebbf3 100644
--- a/Toolkit.Avalonia/ContentControlHandler.cs
+++ b/Toolkit.Avalonia/ContentControlHandler.cs
@@ -14,29 +14,29 @@ public class ContentControlHandler :
if (args.Template is Control control)
{
TaskCompletionSource taskCompletionSource = new();
- async void HandleLoaded(object? sender, RoutedEventArgs args)
+ void HandleLoaded(object? sender, RoutedEventArgs args)
{
control.Loaded -= HandleLoaded;
if (control.DataContext is object content)
{
- //if (content is IActivated activated)
- //{
- // await activated.OnActivated();
- //}
+ if (content is IActivation activation)
+ {
+ activation.IsActive = true;
+ }
}
taskCompletionSource.SetResult();
}
- async void HandleUnloaded(object? sender, RoutedEventArgs args)
+ void HandleUnloaded(object? sender, RoutedEventArgs args)
{
control.Unloaded -= HandleLoaded;
if (control.DataContext is object content)
{
- //if (content is IDeactivated deactivated)
- //{
- // await deactivated.OnDeactivated();
- //}
+ if (content is IActivation activation)
+ {
+ activation.IsActive = false;
+ }
if (content is IDisposable disposable)
{
diff --git a/Toolkit.Avalonia/ContentDialogHandler.cs b/Toolkit.Avalonia/ContentDialogHandler.cs
index 9187995..8033e73 100644
--- a/Toolkit.Avalonia/ContentDialogHandler.cs
+++ b/Toolkit.Avalonia/ContentDialogHandler.cs
@@ -86,10 +86,10 @@ public class ContentDialogHandler :
dialog.Opened -= HandleOpened;
if (dialog.DataContext is object content)
{
- //if (content is IActivated activated)
- //{
- // activated.OnActivated();
- //}
+ if (content is IActivation activation)
+ {
+ activation.IsActive = true;
+ }
}
}
@@ -99,10 +99,10 @@ public class ContentDialogHandler :
dialog.Closed -= HandleClosed;
if (dialog.DataContext is object content)
{
- //if (content is IDeactivated deactivated)
- //{
- // deactivated.OnDeactivated();
- //}
+ if (content is IActivation activation)
+ {
+ activation.IsActive = false;
+ }
}
}
diff --git a/Toolkit.Avalonia/ContentTemplate.cs b/Toolkit.Avalonia/ContentTemplate.cs
index f762bce..3dc3d0f 100644
--- a/Toolkit.Avalonia/ContentTemplate.cs
+++ b/Toolkit.Avalonia/ContentTemplate.cs
@@ -25,38 +25,38 @@ public class ContentTemplate :
{
if (provider.GetRequiredKeyedService(descriptor.TemplateType, descriptor.Key) is Control control)
{
- async void HandleLoaded(object? sender, RoutedEventArgs args)
+ void HandleLoaded(object? sender, RoutedEventArgs args)
{
control.Loaded -= HandleLoaded;
if (control.DataContext is object content)
{
- //if (content is IActivated activated)
- //{
- // await activated.OnActivated();
- //}
+ if (content is IActivation activation)
+ {
+ activation.IsActive = true;
+ }
}
}
- async void HandleDataContextChanged(object? sender, EventArgs args)
+ void HandleDataContextChanged(object? sender, EventArgs args)
{
if (control.DataContext is object content)
{
- //if (content is IActivated activated)
- //{
- // await activated.OnActivated();
- //}
+ if (content is IActivation activation)
+ {
+ activation.IsActive = true;
+ }
}
}
- async void HandleUnloaded(object? sender, RoutedEventArgs args)
+ void HandleUnloaded(object? sender, RoutedEventArgs args)
{
control.Unloaded -= HandleUnloaded;
if (control.DataContext is object content)
{
- //if (content is IDeactivated deactivated)
- //{
- // await deactivated.OnDeactivated();
- //}
+ if (content is IActivation activation)
+ {
+ activation.IsActive = false;
+ }
}
}
@@ -87,38 +87,38 @@ public class ContentTemplate :
{
if (provider.GetRequiredKeyedService(descriptor.TemplateType, descriptor.Key) is Control control)
{
- async void HandleLoaded(object? sender, RoutedEventArgs args)
+ void HandleLoaded(object? sender, RoutedEventArgs args)
{
control.Loaded -= HandleLoaded;
if (control.DataContext is object content)
{
- //if (content is IActivated activated)
- //{
- // await activated.OnActivated();
- //}
+ if (content is IActivation activation)
+ {
+ activation.IsActive = true;
+ }
}
}
- async void HandleDataContextChanged(object? sender, EventArgs args)
+ void HandleDataContextChanged(object? sender, EventArgs args)
{
if (control.DataContext is object content)
{
- //if (content is IActivated activated)
- //{
- // await activated.OnActivated();
- //}
+ if (content is IActivation activation)
+ {
+ activation.IsActive = true;
+ }
}
}
- async void HandleUnloaded(object? sender, RoutedEventArgs args)
+ void HandleUnloaded(object? sender, RoutedEventArgs args)
{
control.Unloaded -= HandleUnloaded;
if (control.DataContext is object content)
{
- //if (content is IDeactivated deactivated)
- //{
- // await deactivated.OnDeactivated();
- //}
+ if (content is IActivation activation)
+ {
+ activation.IsActive = false;
+ }
}
}
diff --git a/Toolkit.Avalonia/FrameHandler.cs b/Toolkit.Avalonia/FrameHandler.cs
index 6d0f4f1..dda22b8 100644
--- a/Toolkit.Avalonia/FrameHandler.cs
+++ b/Toolkit.Avalonia/FrameHandler.cs
@@ -20,22 +20,22 @@ public class FrameHandler(ITransientNavigationStore navigationStore) :
{
void Navigated(Control sender)
{
- async void HandleNavigatedTo(object? _, NavigationEventArgs __)
+ void HandleNavigatedTo(object? _, NavigationEventArgs __)
{
async void HandleNavigatingFrom(object? _, NavigatingCancelEventArgs args)
{
sender.RemoveHandler(Frame.NavigatingFromEvent, HandleNavigatingFrom);
control.Unloaded -= HandleUnloaded;
- async void HandleNavigatedFrom(object? _, NavigationEventArgs args)
+ void HandleNavigatedFrom(object? _, NavigationEventArgs args)
{
sender.RemoveHandler(Frame.NavigatedFromEvent, HandleNavigatedFrom);
if (sender.DataContext is object content)
{
- //if (content is IDeactivated deactivated)
- //{
- // await deactivated.OnDeactivated();
- //}
+ if (content is IActivation activation)
+ {
+ activation.IsActive = false;
+ }
if (content is IDisposable disposable)
{
@@ -58,27 +58,19 @@ public class FrameHandler(ITransientNavigationStore navigationStore) :
{
args.Cancel = true;
}
-
- if (!args.Cancel)
- {
- //if (content is IDeactivating deactivating)
- //{
- // await deactivating.OnDeactivating();
- //}
- }
}
}
sender.AddHandler(Frame.NavigatingFromEvent, HandleNavigatingFrom);
if (sender.DataContext is object content)
{
- //if (content is IActivated activated)
- //{
- // await activated.OnActivated();
- //}
+ if (content is IActivation activation)
+ {
+ activation.IsActive = true;
+ }
}
- async void HandleUnloaded(object? _, RoutedEventArgs __)
+ void HandleUnloaded(object? _, RoutedEventArgs __)
{
sender.RemoveHandler(Frame.NavigatedToEvent, HandleNavigatedTo);
sender.RemoveHandler(Frame.NavigatingFromEvent, HandleNavigatingFrom);
@@ -87,10 +79,10 @@ public class FrameHandler(ITransientNavigationStore navigationStore) :
if (control.DataContext is object content)
{
- //if (content is IDeactivated deactivated)
- //{
- // await deactivated.OnDeactivated();
- //}
+ if (content is IActivation activation)
+ {
+ activation.IsActive = true;
+ }
if (content is IDisposable disposable)
{
diff --git a/Toolkit.Avalonia/TaskDialogHandler.cs b/Toolkit.Avalonia/TaskDialogHandler.cs
index 73a0d65..c4eeb6e 100644
--- a/Toolkit.Avalonia/TaskDialogHandler.cs
+++ b/Toolkit.Avalonia/TaskDialogHandler.cs
@@ -23,8 +23,6 @@ public class TaskDialogHandler(ITopLevelProvider topLevelProvider) :
dialog.Closing -= HandleClosing;
if (dialog.DataContext is object content)
{
- bool cancelled = false;
-
if (args.Result is TaskDialogResult result)
{
if (result is TaskDialogResult.OK && content is
@@ -34,22 +32,12 @@ public class TaskDialogHandler(ITopLevelProvider topLevelProvider) :
if (!await primaryConfirmation.ConfirmPrimary())
{
args.Cancel = true;
- cancelled = true;
-
dialog.Closing += HandleClosing;
}
deferral.Complete();
}
}
-
- if (!cancelled)
- {
- //if (content is IDeactivating deactivating)
- //{
- // await deactivating.OnDeactivating();
- //}
- }
}
}
diff --git a/Toolkit.Foundation/IActivation.cs b/Toolkit.Foundation/IActivation.cs
new file mode 100644
index 0000000..35ceaa1
--- /dev/null
+++ b/Toolkit.Foundation/IActivation.cs
@@ -0,0 +1,6 @@
+namespace Toolkit.Foundation;
+
+public interface IActivation
+{
+ bool IsActive { get; set; }
+}
diff --git a/Toolkit.Foundation/ObservableCollection.cs b/Toolkit.Foundation/ObservableCollection.cs
index aeb48ea..d39678b 100644
--- a/Toolkit.Foundation/ObservableCollection.cs
+++ b/Toolkit.Foundation/ObservableCollection.cs
@@ -25,7 +25,8 @@ public partial class ObservableCollection :
IRecipient>,
IRecipient>,
IRecipient>,
- IRecipient>
+ IRecipient>,
+ IActivation
where TViewModel : notnull,
IDisposable
{
@@ -56,6 +57,7 @@ public partial class ObservableCollection :
Provider = provider;
Factory = factory;
Disposer = disposer;
+ Messenger = messenger;
dispatcher = Provider.GetRequiredService();
collection.CollectionChanged += OnCollectionChanged;
@@ -70,6 +72,7 @@ public partial class ObservableCollection :
Provider = provider;
Factory = factory;
Disposer = disposer;
+ Messenger = messenger;
dispatcher = Provider.GetRequiredService();
collection.CollectionChanged += OnCollectionChanged;
@@ -84,10 +87,15 @@ public partial class ObservableCollection :
public IServiceFactory Factory { get; private set; }
bool IList.IsFixedSize => false;
+
bool ICollection.IsReadOnly => false;
+
bool IList.IsReadOnly => false;
+
bool ICollection.IsSynchronized => false;
+
public new IMessenger Messenger { get; private set; }
+
public IServiceProvider Provider { get; private set; }
object ICollection.SyncRoot => this;