Add activation states back

This commit is contained in:
Dan Clark
2024-11-16 14:05:39 +00:00
parent e45c39030d
commit b4cf6c9928
7 changed files with 78 additions and 84 deletions
+10 -10
View File
@@ -14,29 +14,29 @@ public class ContentControlHandler :
if (args.Template is Control control) if (args.Template is Control control)
{ {
TaskCompletionSource taskCompletionSource = new(); TaskCompletionSource taskCompletionSource = new();
async void HandleLoaded(object? sender, RoutedEventArgs args) void HandleLoaded(object? sender, RoutedEventArgs args)
{ {
control.Loaded -= HandleLoaded; control.Loaded -= HandleLoaded;
if (control.DataContext is object content) if (control.DataContext is object content)
{ {
//if (content is IActivated activated) if (content is IActivation activation)
//{ {
// await activated.OnActivated(); activation.IsActive = true;
//} }
} }
taskCompletionSource.SetResult(); taskCompletionSource.SetResult();
} }
async void HandleUnloaded(object? sender, RoutedEventArgs args) void HandleUnloaded(object? sender, RoutedEventArgs args)
{ {
control.Unloaded -= HandleLoaded; control.Unloaded -= HandleLoaded;
if (control.DataContext is object content) if (control.DataContext is object content)
{ {
//if (content is IDeactivated deactivated) if (content is IActivation activation)
//{ {
// await deactivated.OnDeactivated(); activation.IsActive = false;
//} }
if (content is IDisposable disposable) if (content is IDisposable disposable)
{ {
+8 -8
View File
@@ -86,10 +86,10 @@ public class ContentDialogHandler :
dialog.Opened -= HandleOpened; dialog.Opened -= HandleOpened;
if (dialog.DataContext is object content) if (dialog.DataContext is object content)
{ {
//if (content is IActivated activated) if (content is IActivation activation)
//{ {
// activated.OnActivated(); activation.IsActive = true;
//} }
} }
} }
@@ -99,10 +99,10 @@ public class ContentDialogHandler :
dialog.Closed -= HandleClosed; dialog.Closed -= HandleClosed;
if (dialog.DataContext is object content) if (dialog.DataContext is object content)
{ {
//if (content is IDeactivated deactivated) if (content is IActivation activation)
//{ {
// deactivated.OnDeactivated(); activation.IsActive = false;
//} }
} }
} }
+30 -30
View File
@@ -25,38 +25,38 @@ public class ContentTemplate :
{ {
if (provider.GetRequiredKeyedService(descriptor.TemplateType, descriptor.Key) is Control control) 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; control.Loaded -= HandleLoaded;
if (control.DataContext is object content) if (control.DataContext is object content)
{ {
//if (content is IActivated activated) if (content is IActivation activation)
//{ {
// await activated.OnActivated(); activation.IsActive = true;
//} }
} }
} }
async void HandleDataContextChanged(object? sender, EventArgs args) void HandleDataContextChanged(object? sender, EventArgs args)
{ {
if (control.DataContext is object content) if (control.DataContext is object content)
{ {
//if (content is IActivated activated) if (content is IActivation activation)
//{ {
// await activated.OnActivated(); activation.IsActive = true;
//} }
} }
} }
async void HandleUnloaded(object? sender, RoutedEventArgs args) void HandleUnloaded(object? sender, RoutedEventArgs args)
{ {
control.Unloaded -= HandleUnloaded; control.Unloaded -= HandleUnloaded;
if (control.DataContext is object content) if (control.DataContext is object content)
{ {
//if (content is IDeactivated deactivated) if (content is IActivation activation)
//{ {
// await deactivated.OnDeactivated(); activation.IsActive = false;
//} }
} }
} }
@@ -87,38 +87,38 @@ public class ContentTemplate :
{ {
if (provider.GetRequiredKeyedService(descriptor.TemplateType, descriptor.Key) is Control control) 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; control.Loaded -= HandleLoaded;
if (control.DataContext is object content) if (control.DataContext is object content)
{ {
//if (content is IActivated activated) if (content is IActivation activation)
//{ {
// await activated.OnActivated(); activation.IsActive = true;
//} }
} }
} }
async void HandleDataContextChanged(object? sender, EventArgs args) void HandleDataContextChanged(object? sender, EventArgs args)
{ {
if (control.DataContext is object content) if (control.DataContext is object content)
{ {
//if (content is IActivated activated) if (content is IActivation activation)
//{ {
// await activated.OnActivated(); activation.IsActive = true;
//} }
} }
} }
async void HandleUnloaded(object? sender, RoutedEventArgs args) void HandleUnloaded(object? sender, RoutedEventArgs args)
{ {
control.Unloaded -= HandleUnloaded; control.Unloaded -= HandleUnloaded;
if (control.DataContext is object content) if (control.DataContext is object content)
{ {
//if (content is IDeactivated deactivated) if (content is IActivation activation)
//{ {
// await deactivated.OnDeactivated(); activation.IsActive = false;
//} }
} }
} }
+15 -23
View File
@@ -20,22 +20,22 @@ public class FrameHandler(ITransientNavigationStore<Frame> navigationStore) :
{ {
void Navigated(Control sender) void Navigated(Control sender)
{ {
async void HandleNavigatedTo(object? _, NavigationEventArgs __) void HandleNavigatedTo(object? _, NavigationEventArgs __)
{ {
async void HandleNavigatingFrom(object? _, NavigatingCancelEventArgs args) async void HandleNavigatingFrom(object? _, NavigatingCancelEventArgs args)
{ {
sender.RemoveHandler(Frame.NavigatingFromEvent, HandleNavigatingFrom); sender.RemoveHandler(Frame.NavigatingFromEvent, HandleNavigatingFrom);
control.Unloaded -= HandleUnloaded; control.Unloaded -= HandleUnloaded;
async void HandleNavigatedFrom(object? _, NavigationEventArgs args) void HandleNavigatedFrom(object? _, NavigationEventArgs args)
{ {
sender.RemoveHandler(Frame.NavigatedFromEvent, HandleNavigatedFrom); sender.RemoveHandler(Frame.NavigatedFromEvent, HandleNavigatedFrom);
if (sender.DataContext is object content) if (sender.DataContext is object content)
{ {
//if (content is IDeactivated deactivated) if (content is IActivation activation)
//{ {
// await deactivated.OnDeactivated(); activation.IsActive = false;
//} }
if (content is IDisposable disposable) if (content is IDisposable disposable)
{ {
@@ -58,27 +58,19 @@ public class FrameHandler(ITransientNavigationStore<Frame> navigationStore) :
{ {
args.Cancel = true; args.Cancel = true;
} }
if (!args.Cancel)
{
//if (content is IDeactivating deactivating)
//{
// await deactivating.OnDeactivating();
//}
}
} }
} }
sender.AddHandler(Frame.NavigatingFromEvent, HandleNavigatingFrom); sender.AddHandler(Frame.NavigatingFromEvent, HandleNavigatingFrom);
if (sender.DataContext is object content) if (sender.DataContext is object content)
{ {
//if (content is IActivated activated) if (content is IActivation activation)
//{ {
// await activated.OnActivated(); activation.IsActive = true;
//} }
} }
async void HandleUnloaded(object? _, RoutedEventArgs __) void HandleUnloaded(object? _, RoutedEventArgs __)
{ {
sender.RemoveHandler(Frame.NavigatedToEvent, HandleNavigatedTo); sender.RemoveHandler(Frame.NavigatedToEvent, HandleNavigatedTo);
sender.RemoveHandler(Frame.NavigatingFromEvent, HandleNavigatingFrom); sender.RemoveHandler(Frame.NavigatingFromEvent, HandleNavigatingFrom);
@@ -87,10 +79,10 @@ public class FrameHandler(ITransientNavigationStore<Frame> navigationStore) :
if (control.DataContext is object content) if (control.DataContext is object content)
{ {
//if (content is IDeactivated deactivated) if (content is IActivation activation)
//{ {
// await deactivated.OnDeactivated(); activation.IsActive = true;
//} }
if (content is IDisposable disposable) if (content is IDisposable disposable)
{ {
-12
View File
@@ -23,8 +23,6 @@ public class TaskDialogHandler(ITopLevelProvider topLevelProvider) :
dialog.Closing -= HandleClosing; dialog.Closing -= HandleClosing;
if (dialog.DataContext is object content) if (dialog.DataContext is object content)
{ {
bool cancelled = false;
if (args.Result is TaskDialogResult result) if (args.Result is TaskDialogResult result)
{ {
if (result is TaskDialogResult.OK && content is if (result is TaskDialogResult.OK && content is
@@ -34,22 +32,12 @@ public class TaskDialogHandler(ITopLevelProvider topLevelProvider) :
if (!await primaryConfirmation.ConfirmPrimary()) if (!await primaryConfirmation.ConfirmPrimary())
{ {
args.Cancel = true; args.Cancel = true;
cancelled = true;
dialog.Closing += HandleClosing; dialog.Closing += HandleClosing;
} }
deferral.Complete(); deferral.Complete();
} }
} }
if (!cancelled)
{
//if (content is IDeactivating deactivating)
//{
// await deactivating.OnDeactivating();
//}
}
} }
} }
+6
View File
@@ -0,0 +1,6 @@
namespace Toolkit.Foundation;
public interface IActivation
{
bool IsActive { get; set; }
}
+9 -1
View File
@@ -25,7 +25,8 @@ public partial class ObservableCollection<TViewModel> :
IRecipient<InsertEventArgs<TViewModel>>, IRecipient<InsertEventArgs<TViewModel>>,
IRecipient<MoveEventArgs<TViewModel>>, IRecipient<MoveEventArgs<TViewModel>>,
IRecipient<MoveToEventArgs<TViewModel>>, IRecipient<MoveToEventArgs<TViewModel>>,
IRecipient<ReplaceEventArgs<TViewModel>> IRecipient<ReplaceEventArgs<TViewModel>>,
IActivation
where TViewModel : notnull, where TViewModel : notnull,
IDisposable IDisposable
{ {
@@ -56,6 +57,7 @@ public partial class ObservableCollection<TViewModel> :
Provider = provider; Provider = provider;
Factory = factory; Factory = factory;
Disposer = disposer; Disposer = disposer;
Messenger = messenger;
dispatcher = Provider.GetRequiredService<IDispatcher>(); dispatcher = Provider.GetRequiredService<IDispatcher>();
collection.CollectionChanged += OnCollectionChanged; collection.CollectionChanged += OnCollectionChanged;
@@ -70,6 +72,7 @@ public partial class ObservableCollection<TViewModel> :
Provider = provider; Provider = provider;
Factory = factory; Factory = factory;
Disposer = disposer; Disposer = disposer;
Messenger = messenger;
dispatcher = Provider.GetRequiredService<IDispatcher>(); dispatcher = Provider.GetRequiredService<IDispatcher>();
collection.CollectionChanged += OnCollectionChanged; collection.CollectionChanged += OnCollectionChanged;
@@ -84,10 +87,15 @@ public partial class ObservableCollection<TViewModel> :
public IServiceFactory Factory { get; private set; } public IServiceFactory Factory { get; private set; }
bool IList.IsFixedSize => false; bool IList.IsFixedSize => false;
bool ICollection<TViewModel>.IsReadOnly => false; bool ICollection<TViewModel>.IsReadOnly => false;
bool IList.IsReadOnly => false; bool IList.IsReadOnly => false;
bool ICollection.IsSynchronized => false; bool ICollection.IsSynchronized => false;
public new IMessenger Messenger { get; private set; } public new IMessenger Messenger { get; private set; }
public IServiceProvider Provider { get; private set; } public IServiceProvider Provider { get; private set; }
object ICollection.SyncRoot => this; object ICollection.SyncRoot => this;