Wire up settings
This commit is contained in:
@@ -10,6 +10,11 @@ public class WindowHandler :
|
||||
{
|
||||
if (args.Template is Window window)
|
||||
{
|
||||
if (window.Content is FrameworkElement frameworkElement)
|
||||
{
|
||||
frameworkElement.DataContext = args.Content;
|
||||
}
|
||||
|
||||
window.Activate();
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public partial class App :
|
||||
services.AddContentTemplate<SecondaryViewModel, SecondaryView>();
|
||||
|
||||
services.AddContentTemplate<SettingsButtonViewModel, SettingsButtonView>();
|
||||
services.AddContentTemplate<SettingsView, SettingsView>("Settings");
|
||||
services.AddContentTemplate<SettingsViewModel, SettingsView>("Settings");
|
||||
|
||||
services.AddTransient<IInitializer, AppInitializer>();
|
||||
})
|
||||
|
||||
@@ -2,6 +2,20 @@
|
||||
<Window
|
||||
x:Class="Hyperbar.Windows.SettingsView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<Button>afsdfdg</Button>
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:hyperbar="using:Hyperbar">
|
||||
<Window.SystemBackdrop>
|
||||
<MicaBackdrop />
|
||||
</Window.SystemBackdrop>
|
||||
<NavigationView
|
||||
IsBackButtonVisible="Collapsed"
|
||||
IsPaneToggleButtonVisible="False"
|
||||
IsSettingsVisible="False"
|
||||
MenuItemsSource="{x:Bind ViewModel, Mode=OneWay}">
|
||||
<NavigationView.MenuItemTemplate>
|
||||
<DataTemplate x:DataType="hyperbar:NavigationViewModel">
|
||||
<NavigationViewItem Content="{x:Bind Text, Mode=OneWay}" />
|
||||
</DataTemplate>
|
||||
</NavigationView.MenuItemTemplate>
|
||||
</NavigationView>
|
||||
</Window>
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace Hyperbar.Windows
|
||||
{
|
||||
public sealed partial class SettingsView :
|
||||
namespace Hyperbar.Windows;
|
||||
|
||||
public partial class SettingsView :
|
||||
Window
|
||||
{
|
||||
public SettingsView() =>
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected SettingsViewModel ViewModel =>
|
||||
(SettingsViewModel)(Content as FrameworkElement)!.DataContext;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Hyperbar.Windows;
|
||||
|
||||
namespace Hyperbar.Windows
|
||||
public partial class SettingsViewModel :
|
||||
ObservableCollectionViewModel<NavigationViewModel>
|
||||
{
|
||||
internal class SettingsViewModel
|
||||
public SettingsViewModel(IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer) : base(serviceFactory, mediator, disposer)
|
||||
{
|
||||
Add<NavigationViewModel>("General");
|
||||
Add<NavigationViewModel>("Widgets");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,13 +34,14 @@ public class NavigateHandler :
|
||||
contentTemplateDescriptor.TemplateType.BaseType == navigationDescriptor.Type)
|
||||
{
|
||||
if (provider.GetRequiredKeyedService(contentTemplateDescriptor.TemplateType,
|
||||
contentTemplateDescriptor.Key) is { } template)
|
||||
contentTemplateDescriptor.Key) is { } template &&
|
||||
provider.GetRequiredKeyedService(contentTemplateDescriptor.ContentType,
|
||||
contentTemplateDescriptor.Key) is { } content)
|
||||
{
|
||||
Type navigateType = typeof(Navigate<>)
|
||||
.MakeGenericType(navigationDescriptor.Type);
|
||||
|
||||
if (Activator.CreateInstance(navigateType,
|
||||
new object[] { template, args.Key }) is object navigate)
|
||||
new object[] { template, content }) is object navigate)
|
||||
{
|
||||
await mediator.PublishAsync(navigate, cancellationToken);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace Hyperbar;
|
||||
|
||||
public partial class NavigationViewModel :
|
||||
ObservableCollectionViewModel<NavigationViewModel>
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string? text;
|
||||
|
||||
public NavigationViewModel(IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
string text) : base(serviceFactory, mediator, disposer)
|
||||
{
|
||||
this.text = text;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user