WIP
This commit is contained in:
@@ -10,14 +10,18 @@ public class ClassicDesktopStyleApplicationHandler :
|
||||
{
|
||||
public void Handle(NavigateTemplateEventArgs args)
|
||||
{
|
||||
if (Application.Current?.ApplicationLifetime is
|
||||
IClassicDesktopStyleApplicationLifetime lifeTime)
|
||||
if (Application.Current?.ApplicationLifetime
|
||||
is not IClassicDesktopStyleApplicationLifetime lifeTime)
|
||||
{
|
||||
if (args.Template is Window window)
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Template is not Window window)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lifeTime.MainWindow = window;
|
||||
window.DataContext = args.Content;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,11 +9,16 @@ public class ContentControlHandler :
|
||||
{
|
||||
public void Handle(NavigateTemplateEventArgs args)
|
||||
{
|
||||
if (args.Region is ContentControl contentControl)
|
||||
if (args.Region is not ContentControl contentControl)
|
||||
{
|
||||
if (args.Template is Control control)
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Template is not Control control)
|
||||
{
|
||||
TaskCompletionSource taskCompletionSource = new();
|
||||
return;
|
||||
}
|
||||
|
||||
void HandleLoaded(object? sender, RoutedEventArgs args)
|
||||
{
|
||||
control.Loaded -= HandleLoaded;
|
||||
@@ -24,8 +29,6 @@ public class ContentControlHandler :
|
||||
activation.IsActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
taskCompletionSource.SetResult();
|
||||
}
|
||||
|
||||
void HandleUnloaded(object? sender, RoutedEventArgs args)
|
||||
@@ -53,6 +56,4 @@ public class ContentControlHandler :
|
||||
contentControl.Content = null;
|
||||
contentControl.Content = control;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,9 +114,6 @@ public class ContentDialogHandler :
|
||||
dialog.SecondaryButtonClick += HandleSecondaryButtonClick;
|
||||
|
||||
await dialog.ShowAsync();
|
||||
|
||||
dialog.PrimaryButtonClick += HandlePrimaryButtonClick;
|
||||
dialog.SecondaryButtonClick += HandleSecondaryButtonClick;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,11 +13,18 @@ public class FrameHandler(ITransientNavigationStore<Frame> navigationStore) :
|
||||
{
|
||||
public void Handle(NavigateTemplateEventArgs args)
|
||||
{
|
||||
if (args.Region is Frame frame)
|
||||
if (args.Region is not Frame frame)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Template is not Control control)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
frame.NavigationPageFactory ??= new NavigationPageFactory();
|
||||
if (args.Template is Control control)
|
||||
{
|
||||
|
||||
void Navigated(Control sender)
|
||||
{
|
||||
void HandleNavigatedTo(object? _, NavigationEventArgs __)
|
||||
@@ -197,8 +204,6 @@ public class FrameHandler(ITransientNavigationStore<Frame> navigationStore) :
|
||||
postAction.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Handle(NavigateBackEventArgs<Frame> args)
|
||||
{
|
||||
|
||||
@@ -6,10 +6,3 @@ public record NavigateEventArgs(string Route,
|
||||
object? Sender = null,
|
||||
EventHandler? Navigated = null,
|
||||
IDictionary<string, object>? Parameters = null);
|
||||
|
||||
|
||||
public record NavigateTemplateEventArgs(object Region,
|
||||
object Template,
|
||||
object Content,
|
||||
object? Sender = null,
|
||||
IDictionary<string, object>? Parameters = null);
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record NavigateTemplateEventArgs(object Region,
|
||||
object Template,
|
||||
object Content,
|
||||
object? Sender = null,
|
||||
IDictionary<string, object>? Parameters = null);
|
||||
@@ -37,8 +37,7 @@ public class Navigation(IServiceProvider provider,
|
||||
.GetConstructors()
|
||||
.FirstOrDefault()?
|
||||
.GetParameters()
|
||||
.Select(x =>
|
||||
x?.Name is not null && arguments is not null && arguments.TryGetValue(x.Name, out object? argument)
|
||||
.Select(x => x?.Name is not null && arguments is not null && arguments.TryGetValue(x.Name, out object? argument)
|
||||
? argument
|
||||
: null)
|
||||
.Where(argument => argument is not null)
|
||||
@@ -70,9 +69,7 @@ public class Navigation(IServiceProvider provider,
|
||||
object? content = contentFactory.Create(descriptor, resolvedArguments);
|
||||
if (content is not null)
|
||||
{
|
||||
Type navigationType = region is Type type ? type : region.GetType();
|
||||
|
||||
messenger.Send(new NavigateTemplateEventArgs(region, template, content, sender, parameters), navigationType.Name);
|
||||
messenger.Send(new NavigateTemplateEventArgs(region, template, content, sender, parameters), region is string ? $"{region}" : region.GetType().Name);
|
||||
if (currentSegmentIndex == segmentCount)
|
||||
{
|
||||
navigated?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
@@ -75,7 +75,7 @@ public class NavigateAction :
|
||||
ImmutableDictionary<string, object>.Empty;
|
||||
|
||||
observableViewModel.Messenger.Send(new NavigateEventArgs(Route, Region.Equals(this) ? content : Region, Scope ?? null,
|
||||
content.DataContext, Navigated, parameters));
|
||||
content, Navigated, parameters));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,11 +9,16 @@ public class ContentControlHandler :
|
||||
{
|
||||
public void Handle(NavigateTemplateEventArgs args)
|
||||
{
|
||||
if (args.Region is ContentControl contentControl)
|
||||
if (args.Region is not ContentControl contentControl)
|
||||
{
|
||||
if (args.Template is Control control)
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Template is not Control control)
|
||||
{
|
||||
TaskCompletionSource taskCompletionSource = new();
|
||||
return;
|
||||
}
|
||||
|
||||
void HandleLoaded(object? sender, RoutedEventArgs args)
|
||||
{
|
||||
control.Loaded -= HandleLoaded;
|
||||
@@ -24,8 +29,6 @@ public class ContentControlHandler :
|
||||
activation.IsActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
taskCompletionSource.SetResult();
|
||||
}
|
||||
|
||||
void HandleUnloaded(object? sender, RoutedEventArgs args)
|
||||
@@ -49,10 +52,6 @@ public class ContentControlHandler :
|
||||
control.Unloaded += HandleUnloaded;
|
||||
|
||||
control.DataContext = args.Content;
|
||||
|
||||
contentControl.Content = null;
|
||||
contentControl.Content = control;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Toolkit.WinUI;
|
||||
@@ -8,8 +9,19 @@ public class ContentDialogHandler :
|
||||
{
|
||||
public async void Handle(NavigateTemplateEventArgs args)
|
||||
{
|
||||
if (args.Template is ContentDialog dialog)
|
||||
if (args.Template is not ContentDialog dialog)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.Sender is not Control parent)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
dialog.XamlRoot = parent.XamlRoot;
|
||||
dialog.Style = Application.Current.Resources["DefaultContentDialogStyle"] as Style;
|
||||
|
||||
dialog.DataContext = args.Content;
|
||||
|
||||
async void HandlePrimaryButtonClick(ContentDialog sender,
|
||||
@@ -110,9 +122,5 @@ public class ContentDialogHandler :
|
||||
dialog.SecondaryButtonClick += HandleSecondaryButtonClick;
|
||||
|
||||
await dialog.ShowAsync();
|
||||
|
||||
dialog.PrimaryButtonClick += HandlePrimaryButtonClick;
|
||||
dialog.SecondaryButtonClick += HandleSecondaryButtonClick;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user