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