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)
{
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)
{
+8 -8
View File
@@ -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;
}
}
}
+30 -30
View File
@@ -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;
}
}
}
+15 -23
View File
@@ -20,22 +20,22 @@ public class FrameHandler(ITransientNavigationStore<Frame> 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<Frame> 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<Frame> 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)
{
-12
View File
@@ -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();
//}
}
}
}
+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<MoveEventArgs<TViewModel>>,
IRecipient<MoveToEventArgs<TViewModel>>,
IRecipient<ReplaceEventArgs<TViewModel>>
IRecipient<ReplaceEventArgs<TViewModel>>,
IActivation
where TViewModel : notnull,
IDisposable
{
@@ -56,6 +57,7 @@ public partial class ObservableCollection<TViewModel> :
Provider = provider;
Factory = factory;
Disposer = disposer;
Messenger = messenger;
dispatcher = Provider.GetRequiredService<IDispatcher>();
collection.CollectionChanged += OnCollectionChanged;
@@ -70,6 +72,7 @@ public partial class ObservableCollection<TViewModel> :
Provider = provider;
Factory = factory;
Disposer = disposer;
Messenger = messenger;
dispatcher = Provider.GetRequiredService<IDispatcher>();
collection.CollectionChanged += OnCollectionChanged;
@@ -84,10 +87,15 @@ public partial class ObservableCollection<TViewModel> :
public IServiceFactory Factory { get; private set; }
bool IList.IsFixedSize => false;
bool ICollection<TViewModel>.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;