moer changes
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240124002-experimental2" />
|
||||
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26031-preview" />
|
||||
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Hyperbar.Interop.Windows\Hyperbar.Interop.Windows.csproj" />
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Hyperbar.UI.Windows;
|
||||
|
||||
public interface IViewModelTemplate
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.Xaml.Interactivity;
|
||||
|
||||
namespace Hyperbar.UI.Windows;
|
||||
|
||||
public sealed class NavigateAction :
|
||||
DependencyObject,
|
||||
IAction
|
||||
{
|
||||
public static readonly DependencyProperty PathProperty =
|
||||
DependencyProperty.Register(nameof(Path),
|
||||
typeof(string), typeof(NavigateAction),
|
||||
new PropertyMetadata(null));
|
||||
|
||||
public string Path
|
||||
{
|
||||
get => (string)GetValue(PathProperty);
|
||||
set => SetValue(PathProperty, value);
|
||||
}
|
||||
|
||||
public object Execute(object sender, object parameter)
|
||||
{
|
||||
if (sender is FrameworkElement frameworkElement)
|
||||
{
|
||||
if (frameworkElement.DataContext is IObservableViewModel observableViewModel)
|
||||
{
|
||||
observableViewModel.Mediator.PublishAsync(new Navigate(Path))
|
||||
.GetAwaiter().GetResult();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Markup;
|
||||
|
||||
namespace Hyperbar.UI.Windows;
|
||||
|
||||
public class ViewModelTemplate(IViewModelTemplateDescriptorProvider descriptors) :
|
||||
DataTemplateSelector,
|
||||
IViewModelTemplate
|
||||
{
|
||||
protected override DataTemplate SelectTemplateCore(object item)
|
||||
{
|
||||
return descriptors.Get(item.GetType().Name) is IViewModelTemplateDescriptor descriptor
|
||||
? CreateDataTemplate(descriptor)
|
||||
: new DataTemplate();
|
||||
}
|
||||
|
||||
protected override DataTemplate SelectTemplateCore(object item,
|
||||
DependencyObject container) =>
|
||||
SelectTemplateCore(item);
|
||||
|
||||
private DataTemplate CreateDataTemplate(IViewModelTemplateDescriptor descriptor)
|
||||
{
|
||||
string xamlString = @$"
|
||||
<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
|
||||
xmlns:ui=""using:{descriptor.TemplateType.Namespace}"">
|
||||
<ui:{descriptor.TemplateType.Name} />
|
||||
</DataTemplate>";
|
||||
|
||||
return (DataTemplate)XamlReader.Load(xamlString);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace Hyperbar.UI.Windows;
|
||||
|
||||
public class ViewModelTemplatePresenter :
|
||||
ContentPresenter
|
||||
{
|
||||
public ViewModelTemplatePresenter()
|
||||
{
|
||||
DataContextChanged += OnDataContextChanged;
|
||||
}
|
||||
|
||||
private void OnDataContextChanged(FrameworkElement sender,
|
||||
DataContextChangedEventArgs args)
|
||||
{
|
||||
//if (DataContext is IViewModelTemplate templatedViewModel)
|
||||
//{
|
||||
// Content = templatedViewModel.TemplateFactory
|
||||
// .Create(DataContext.GetType().Name);
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Markup;
|
||||
|
||||
namespace Hyperbar.UI.Windows;
|
||||
|
||||
public class ViewModelTemplate :
|
||||
MarkupExtension
|
||||
{
|
||||
protected override object ProvideValue(IXamlServiceProvider serviceProvider) =>
|
||||
new ViewModelTemplateSelector();
|
||||
|
||||
internal class ViewModelTemplateSelector :
|
||||
DataTemplateSelector
|
||||
{
|
||||
protected override DataTemplate SelectTemplateCore(object item) =>
|
||||
item is IObservableViewModel observableViewModel &&
|
||||
observableViewModel.ServiceProvider.GetService<IViewModelTemplateDescriptorProvider>()
|
||||
is ViewModelTemplateDescriptorProvider descriptors &&
|
||||
descriptors.Get(item.GetType().Name) is IViewModelTemplateDescriptor descriptor
|
||||
? CreateDataTemplate(descriptor)
|
||||
: new DataTemplate();
|
||||
|
||||
protected override DataTemplate SelectTemplateCore(object item,
|
||||
DependencyObject container) =>
|
||||
SelectTemplateCore(item);
|
||||
|
||||
private DataTemplate CreateDataTemplate(IViewModelTemplateDescriptor descriptor)
|
||||
{
|
||||
string xamlString = @$"
|
||||
<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
|
||||
xmlns:ui=""using:{descriptor.TemplateType.Namespace}"">
|
||||
<ui:{descriptor.TemplateType.Name} />
|
||||
</DataTemplate>";
|
||||
|
||||
return (DataTemplate)XamlReader.Load(xamlString);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,19 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace Hyperbar.UI.Windows;
|
||||
|
||||
public class FrameHandler :
|
||||
INavigationHandler<Frame>
|
||||
{
|
||||
public Task Handle(Navigate<Frame> args,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
public class WindowHandler :
|
||||
INavigationHandler<Window>
|
||||
{
|
||||
@@ -10,9 +22,19 @@ public class WindowHandler :
|
||||
{
|
||||
if (args.Template is Window window)
|
||||
{
|
||||
if (window.Content is FrameworkElement frameworkElement)
|
||||
if (window.Content is FrameworkElement content)
|
||||
{
|
||||
frameworkElement.DataContext = args.Content;
|
||||
void HandleClosed(object sender, WindowEventArgs args)
|
||||
{
|
||||
window.Closed -= HandleClosed;
|
||||
if (content.DataContext is IObservableViewModel observableViewModel)
|
||||
{
|
||||
observableViewModel.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
window.Closed += HandleClosed;
|
||||
content.DataContext = args.Content;
|
||||
}
|
||||
|
||||
window.Activate();
|
||||
|
||||
@@ -7,9 +7,8 @@ public partial class MediaButtonViewModel<TMediaButton>(IServiceProvider service
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
IViewModelTemplateFactory templateFactory,
|
||||
IRelayCommand invokeCommand) :
|
||||
WidgetComponentViewModel(serviceProvider, serviceFactory, mediator, disposer, templateFactory),
|
||||
WidgetComponentViewModel(serviceProvider, serviceFactory, mediator, disposer),
|
||||
INotificationHandler<Changed<MediaButton<TMediaButton>>>,
|
||||
IMediaButtonViewModel
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<ItemsControl
|
||||
HorizontalAlignment="Right"
|
||||
HorizontalContentAlignment="Right"
|
||||
ItemTemplateSelector="{ui:ViewModelTemplate}"
|
||||
ItemTemplateSelector="{Binding Template}"
|
||||
ItemsSource="{x:Bind ViewModel}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Hyperbar.UI.Windows;
|
||||
|
||||
namespace Hyperbar.Widget.MediaController.Windows;
|
||||
|
||||
@@ -6,13 +7,13 @@ namespace Hyperbar.Widget.MediaController.Windows;
|
||||
public class MediaControllerViewModel :
|
||||
ObservableCollectionViewModel<WidgetComponentViewModel>
|
||||
{
|
||||
public MediaControllerViewModel(IViewModelTemplateFactory templateFactory,
|
||||
public MediaControllerViewModel(IViewModelTemplate template,
|
||||
IServiceProvider serviceProvider,
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer) : base(serviceProvider, serviceFactory, mediator, disposer)
|
||||
{
|
||||
TemplateFactory = templateFactory;
|
||||
Template = template;
|
||||
|
||||
Add<MediaInformationViewModel>();
|
||||
|
||||
@@ -26,5 +27,5 @@ public class MediaControllerViewModel :
|
||||
await mediator.PublishAsync<Request<MediaNext>>()));
|
||||
}
|
||||
|
||||
public IViewModelTemplateFactory TemplateFactory { get; set; }
|
||||
public IViewModelTemplate Template { get; }
|
||||
}
|
||||
@@ -2,10 +2,9 @@
|
||||
<UserControl
|
||||
x:Class="Hyperbar.Widget.MediaController.Windows.MediaControllerWidgetView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="using:Hyperbar.UI.Windows">
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<FlipView
|
||||
Width="360"
|
||||
ItemTemplateSelector="{ui:ViewModelTemplate}"
|
||||
ItemTemplateSelector="{Binding Template}"
|
||||
ItemsSource="{Binding}" />
|
||||
</UserControl>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
namespace Hyperbar.Widget.MediaController.Windows;
|
||||
using Hyperbar.UI.Windows;
|
||||
|
||||
public class MediaControllerWidgetViewModel(IViewModelTemplateFactory templateFactory,
|
||||
namespace Hyperbar.Widget.MediaController.Windows;
|
||||
|
||||
public class MediaControllerWidgetViewModel(IViewModelTemplate template,
|
||||
IServiceProvider serviceProvider,
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
@@ -9,5 +11,5 @@ public class MediaControllerWidgetViewModel(IViewModelTemplateFactory templateFa
|
||||
ObservableCollectionViewModel<MediaControllerViewModel>(serviceProvider, serviceFactory, mediator, disposer, items),
|
||||
IWidgetViewModel
|
||||
{
|
||||
public IViewModelTemplateFactory TemplateFactory => templateFactory;
|
||||
public IViewModelTemplate Template => template;
|
||||
}
|
||||
@@ -5,9 +5,8 @@ namespace Hyperbar.Widget.MediaController.Windows;
|
||||
public partial class MediaInformationViewModel(IServiceProvider serviceProvider,
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
IViewModelTemplateFactory templateFactory) :
|
||||
WidgetComponentViewModel(serviceProvider, serviceFactory, mediator, disposer, templateFactory),
|
||||
IDisposer disposer) :
|
||||
WidgetComponentViewModel(serviceProvider, serviceFactory, mediator, disposer),
|
||||
INotificationHandler<Changed<MediaInformation>>
|
||||
{
|
||||
[ObservableProperty]
|
||||
|
||||
@@ -3,13 +3,9 @@
|
||||
namespace Hyperbar.Widget.Primary.Windows;
|
||||
|
||||
[NotificationHandler(nameof(PrimaryWidgetViewModel))]
|
||||
public class PrimaryWidgetViewModel(IViewModelTemplateFactory templateFactory,
|
||||
IServiceProvider serviceProvider,
|
||||
public class PrimaryWidgetViewModel(IServiceProvider serviceProvider,
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer) :
|
||||
ObservableCollectionViewModel<IWidgetComponentViewModel>(serviceProvider, serviceFactory, mediator, disposer),
|
||||
IWidgetViewModel
|
||||
{
|
||||
public IViewModelTemplateFactory TemplateFactory => templateFactory;
|
||||
}
|
||||
IWidgetViewModel;
|
||||
@@ -2,7 +2,6 @@
|
||||
using Hyperbar.UI.Windows;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.UI.Xaml.Markup;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Hyperbar.Widget.Windows;
|
||||
|
||||
@@ -19,8 +18,8 @@ public static class IServiceCollectionExtensions
|
||||
services.AddSingleton(provider.GetRequiredService<IList<IXamlMetadataProvider>>());
|
||||
services.AddSingleton(provider.GetRequiredService<IDispatcher>());
|
||||
|
||||
services.AddTransient<IViewModelTemplate, ViewModelTemplate>();
|
||||
services.AddTransient<IViewModelTemplateDescriptorProvider, ViewModelTemplateDescriptorProvider>();
|
||||
services.AddTransient<IViewModelTemplateFactory, ViewModelTemplateFactory>();
|
||||
|
||||
services.AddScoped<IVirtualKeyboard, VirtualKeyboard>();
|
||||
services.AddHandler<KeyAcceleratorHandler>();
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
||||
xmlns:ui="using:Hyperbar.UI.Windows">
|
||||
<Grid>
|
||||
<ItemsControl ItemTemplateSelector="{ui:ViewModelTemplate}" ItemsSource="{Binding Mode=TwoWay}">
|
||||
<ItemsControl ItemTemplateSelector="{Binding Template}" ItemsSource="{Binding Mode=TwoWay}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<StackPanel Orientation="Horizontal" Spacing="8" />
|
||||
|
||||
@@ -8,11 +8,10 @@ public partial class WidgetButtonViewModel(IServiceProvider serviceProvider,
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
IViewModelTemplateFactory templateFactory,
|
||||
Guid id,
|
||||
string? text = null,
|
||||
string? icon = null,
|
||||
RelayCommand? invokeCommand = null) : WidgetComponentViewModel(serviceProvider, serviceFactory, mediator, disposer, templateFactory)
|
||||
RelayCommand? invokeCommand = null) : WidgetComponentViewModel(serviceProvider, serviceFactory, mediator, disposer)
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string? icon = icon;
|
||||
|
||||
@@ -8,20 +8,16 @@ public partial class WidgetComponentViewModel :
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
IViewModelTemplateFactory templateFactory,
|
||||
IEnumerable<IWidgetComponentViewModel> items) : base(serviceProvider, serviceFactory, mediator, disposer, items)
|
||||
{
|
||||
TemplateFactory = templateFactory;
|
||||
|
||||
}
|
||||
|
||||
public WidgetComponentViewModel(IServiceProvider serviceProvider,
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
IViewModelTemplateFactory templateFactory) : base(serviceProvider, serviceFactory, mediator, disposer)
|
||||
IDisposer disposer) : base(serviceProvider, serviceFactory, mediator, disposer)
|
||||
{
|
||||
TemplateFactory = templateFactory;
|
||||
}
|
||||
|
||||
public IViewModelTemplateFactory TemplateFactory { get; private set; }
|
||||
}
|
||||
}
|
||||
@@ -8,11 +8,10 @@ public partial class WidgetMenuViewModel(IServiceProvider serviceProvider,
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
IViewModelTemplateFactory templateFactory,
|
||||
Guid id = default,
|
||||
string? text = null,
|
||||
string? icon = null,
|
||||
RelayCommand? command = null) : WidgetComponentViewModel(serviceProvider, serviceFactory, mediator, disposer, templateFactory)
|
||||
RelayCommand? command = null) : WidgetComponentViewModel(serviceProvider, serviceFactory, mediator, disposer)
|
||||
{
|
||||
[ObservableProperty]
|
||||
private IRelayCommand? click = command;
|
||||
|
||||
@@ -8,12 +8,11 @@ public partial class WidgetSplitButtonViewModel(IServiceProvider serviceProvider
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
IViewModelTemplateFactory templateFactory,
|
||||
IEnumerable<IWidgetComponentViewModel> items,
|
||||
Guid id = default,
|
||||
string? text = null,
|
||||
string? icon = null,
|
||||
RelayCommand? command = null) : WidgetComponentViewModel(serviceProvider, serviceFactory, mediator, disposer, templateFactory, items)
|
||||
RelayCommand? command = null) : WidgetComponentViewModel(serviceProvider, serviceFactory, mediator, disposer, items)
|
||||
{
|
||||
[ObservableProperty]
|
||||
private IRelayCommand? click = command;
|
||||
|
||||
@@ -38,8 +38,8 @@ public partial class App :
|
||||
|
||||
services.AddSingleton<IDispatcher>(new Dispatcher(DispatcherQueue.GetForCurrentThread()));
|
||||
|
||||
services.AddTransient<IViewModelTemplate, ViewModelTemplate>();
|
||||
services.AddTransient<IViewModelTemplateDescriptorProvider, ViewModelTemplateDescriptorProvider>();
|
||||
services.AddTransient<IViewModelTemplateFactory, ViewModelTemplateFactory>();
|
||||
|
||||
services.AddHandler<AppConfigurationChangedHandler>();
|
||||
services.AddConfiguration<AppConfiguration>(args =>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
</UserControl.Resources>
|
||||
<ItemsControl
|
||||
Margin="6,0,6,0"
|
||||
ItemTemplateSelector="{ui:ViewModelTemplate}"
|
||||
ItemTemplateSelector="{Binding Template}"
|
||||
ItemsSource="{x:Bind ViewModel, Mode=OneWay}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
|
||||
@@ -1,20 +1,23 @@
|
||||
namespace Hyperbar.Widget;
|
||||
using Hyperbar.UI.Windows;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
|
||||
[NotificationHandler(nameof(IWidgetHostViewModel))]
|
||||
public partial class ApplicationBarViewModel :
|
||||
ObservableCollectionViewModel<IDisposable>
|
||||
{
|
||||
public ApplicationBarViewModel(IViewModelTemplateFactory templateFactory,
|
||||
public ApplicationBarViewModel(IViewModelTemplate template,
|
||||
IServiceProvider serviceProvider,
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer) : base(serviceProvider, serviceFactory, mediator, disposer)
|
||||
{
|
||||
TemplateFactory = templateFactory;
|
||||
Template = template;
|
||||
|
||||
Add<PrimaryViewModel>(0);
|
||||
Add<SecondaryViewModel>(1);
|
||||
}
|
||||
|
||||
public IViewModelTemplateFactory TemplateFactory { get; }
|
||||
public IViewModelTemplate Template { get; }
|
||||
}
|
||||
@@ -3,4 +3,13 @@
|
||||
x:Class="Hyperbar.Windows.GeneralSettingsNavigationView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Content="General" />
|
||||
xmlns:interactions="using:Microsoft.Xaml.Interactions.Core"
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
||||
xmlns:ui="using:Hyperbar.UI.Windows"
|
||||
Content="General">
|
||||
<interactivity:Interaction.Behaviors>
|
||||
<interactions:EventTriggerBehavior EventName="Tapped">
|
||||
<ui:NavigateAction />
|
||||
</interactions:EventTriggerBehavior>
|
||||
</interactivity:Interaction.Behaviors>
|
||||
</NavigationViewItem>
|
||||
|
||||
@@ -2,9 +2,12 @@ using Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace Hyperbar.Windows;
|
||||
|
||||
public sealed partial class GeneralSettingsNavigationView :
|
||||
public partial class GeneralSettingsNavigationView :
|
||||
NavigationViewItem
|
||||
{
|
||||
public GeneralSettingsNavigationView() =>
|
||||
InitializeComponent();
|
||||
|
||||
protected GeneralSettingsNavigationViewModel ViewModel =>
|
||||
(GeneralSettingsNavigationViewModel)DataContext;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
xmlns:ui="using:Hyperbar.UI.Windows">
|
||||
<ItemsControl
|
||||
HorizontalAlignment="Center"
|
||||
ItemTemplateSelector="{ui:ViewModelTemplate}"
|
||||
ItemTemplateSelector="{Binding Template}"
|
||||
ItemsSource="{x:Bind ViewModel}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Hyperbar.UI.Windows;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
[NotificationHandler(nameof(IWidgetHostViewModel))]
|
||||
public partial class PrimaryViewModel(IViewModelTemplateFactory templateFactory,
|
||||
public partial class PrimaryViewModel(IViewModelTemplate template,
|
||||
IServiceProvider serviceProvider,
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
@@ -15,5 +16,6 @@ public partial class PrimaryViewModel(IViewModelTemplateFactory templateFactory,
|
||||
[ObservableProperty]
|
||||
private int index = index;
|
||||
|
||||
public IViewModelTemplateFactory TemplateFactory => templateFactory;
|
||||
public IViewModelTemplate Template => template;
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="using:Hyperbar.UI.Windows">
|
||||
<Grid>
|
||||
<ItemsControl ItemTemplateSelector="{ui:ViewModelTemplate}" ItemsSource="{x:Bind ViewModel, Mode=OneWay}">
|
||||
<ItemsControl ItemTemplateSelector="{Binding Template}" ItemsSource="{x:Bind ViewModel, Mode=OneWay}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<ItemsStackPanel Orientation="Horizontal" />
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Hyperbar.UI.Windows;
|
||||
using Hyperbar.Windows;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
@@ -9,18 +10,19 @@ public partial class SecondaryViewModel :
|
||||
[ObservableProperty]
|
||||
private int index;
|
||||
|
||||
public SecondaryViewModel(IViewModelTemplateFactory templateFactory,
|
||||
public SecondaryViewModel(IViewModelTemplate template,
|
||||
IServiceProvider serviceProvider,
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
int index) : base(serviceProvider, serviceFactory, mediator, disposer)
|
||||
{
|
||||
TemplateFactory = templateFactory;
|
||||
Template = template;
|
||||
this.index = index;
|
||||
|
||||
Add<SettingsButtonViewModel>();
|
||||
}
|
||||
|
||||
public IViewModelTemplateFactory TemplateFactory { get; }
|
||||
public IViewModelTemplate Template { get; }
|
||||
|
||||
}
|
||||
@@ -2,7 +2,10 @@
|
||||
<UserControl
|
||||
x:Class="Hyperbar.Windows.SettingsButtonView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:interactions="using:Microsoft.Xaml.Interactions.Core"
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
||||
xmlns:windows="using:Hyperbar.UI.Windows">
|
||||
<UserControl.Resources>
|
||||
<SolidColorBrush x:Key="ButtonBackground" Color="Transparent" />
|
||||
<SolidColorBrush x:Key="ButtonBorderBrush" Color="Transparent" />
|
||||
@@ -18,8 +21,13 @@
|
||||
Width="{ThemeResource ButtonWidth}"
|
||||
Height="{ThemeResource ButtonHeight}"
|
||||
Padding="{ThemeResource ButtonPadding}"
|
||||
Command="{x:Bind ViewModel.InvokeCommand}"
|
||||
Content=""
|
||||
FontFamily="{ThemeResource SymbolThemeFontFamily}"
|
||||
FontSize="16" />
|
||||
FontSize="16">
|
||||
<interactivity:Interaction.Behaviors>
|
||||
<interactions:EventTriggerBehavior EventName="Click">
|
||||
<windows:NavigateAction Path="Settings" />
|
||||
</interactions:EventTriggerBehavior>
|
||||
</interactivity:Interaction.Behaviors>
|
||||
</Button>
|
||||
</UserControl>
|
||||
|
||||
@@ -1,24 +1,13 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Hyperbar.UI.Windows;
|
||||
|
||||
namespace Hyperbar.Windows;
|
||||
|
||||
public partial class SettingsButtonViewModel :
|
||||
ObservableViewModel
|
||||
{
|
||||
[ObservableProperty]
|
||||
private IRelayCommand? invokeCommand;
|
||||
|
||||
public SettingsButtonViewModel(IViewModelTemplateFactory templateFactory,
|
||||
public partial class SettingsButtonViewModel(IViewModelTemplate template,
|
||||
IServiceProvider serviceProvider,
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer) : base(serviceProvider, serviceFactory, mediator, disposer)
|
||||
IDisposer disposer) :
|
||||
ObservableViewModel(serviceProvider, serviceFactory, mediator, disposer)
|
||||
{
|
||||
TemplateFactory = templateFactory;
|
||||
InvokeCommand = new AsyncRelayCommand(async () =>
|
||||
await mediator.PublishAsync(new Navigate("Settings")));
|
||||
}
|
||||
|
||||
public IViewModelTemplateFactory TemplateFactory { get; }
|
||||
public IViewModelTemplate Template => template;
|
||||
}
|
||||
@@ -2,9 +2,7 @@
|
||||
<Window
|
||||
x:Class="Hyperbar.Windows.SettingsView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="using:Hyperbar.UI.Windows"
|
||||
xmlns:windows="using:Hyperbar.Windows">
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<Window.SystemBackdrop>
|
||||
<MicaBackdrop />
|
||||
</Window.SystemBackdrop>
|
||||
@@ -12,6 +10,6 @@
|
||||
IsBackButtonVisible="Collapsed"
|
||||
IsPaneToggleButtonVisible="False"
|
||||
IsSettingsVisible="False"
|
||||
MenuItemTemplateSelector="{ui:ViewModelTemplate}"
|
||||
MenuItemTemplateSelector="{Binding Template}"
|
||||
MenuItemsSource="{x:Bind ViewModel, Mode=OneWay}" />
|
||||
</Window>
|
||||
@@ -1,19 +1,21 @@
|
||||
namespace Hyperbar.Windows;
|
||||
using Hyperbar.UI.Windows;
|
||||
|
||||
namespace Hyperbar.Windows;
|
||||
|
||||
public partial class SettingsViewModel :
|
||||
ObservableCollectionViewModel<INavigationViewModel>
|
||||
{
|
||||
public SettingsViewModel(IServiceProvider serviceProvider,
|
||||
public SettingsViewModel(IViewModelTemplate template,
|
||||
IServiceProvider serviceProvider,
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
IViewModelTemplateFactory templateFactory) : base(serviceProvider, serviceFactory, mediator, disposer)
|
||||
IDisposer disposer) : base(serviceProvider, serviceFactory, mediator, disposer)
|
||||
{
|
||||
Template = template;
|
||||
|
||||
Add<GeneralSettingsNavigationViewModel>("General");
|
||||
Add<WidgetSettingsNavigationViewModel>("Widgets");
|
||||
|
||||
TemplateFactory = templateFactory;
|
||||
}
|
||||
|
||||
public IViewModelTemplateFactory TemplateFactory { get; }
|
||||
public IViewModelTemplate Template { get; }
|
||||
}
|
||||
|
||||
@@ -3,4 +3,13 @@
|
||||
x:Class="Hyperbar.Windows.WidgetSettingsNavigationView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Content="Widgets" />
|
||||
xmlns:interactions="using:Microsoft.Xaml.Interactions.Core"
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
||||
xmlns:ui="using:Hyperbar.UI.Windows"
|
||||
Content="Widgets">
|
||||
<interactivity:Interaction.Behaviors>
|
||||
<interactions:EventTriggerBehavior EventName="Tapped">
|
||||
<ui:NavigateAction />
|
||||
</interactions:EventTriggerBehavior>
|
||||
</interactivity:Interaction.Behaviors>
|
||||
</NavigationViewItem>
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
using Hyperbar.Widget;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace Hyperbar.Windows;
|
||||
|
||||
public sealed partial class WidgetSettingsNavigationView :
|
||||
public partial class WidgetSettingsNavigationView :
|
||||
NavigationViewItem
|
||||
{
|
||||
public WidgetSettingsNavigationView() =>
|
||||
InitializeComponent();
|
||||
|
||||
protected WidgetSettingsNavigationViewModel ViewModel =>
|
||||
(WidgetSettingsNavigationViewModel)DataContext;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Hyperbar;
|
||||
public class NavigateHandler :
|
||||
INotificationHandler<Navigate>
|
||||
{
|
||||
private readonly IEnumerable<IViewModelTemplateDescriptor> contentTemplateDescriptors;
|
||||
private readonly IViewModelTemplateDescriptorProvider contentTemplateDescriptors;
|
||||
private readonly IServiceProvider provider;
|
||||
private readonly IMediator mediator;
|
||||
private readonly IEnumerable<INavigationDescriptor> navigationDescriptors;
|
||||
@@ -13,7 +13,7 @@ public class NavigateHandler :
|
||||
public NavigateHandler(IServiceProvider provider,
|
||||
IMediator mediator,
|
||||
IEnumerable<INavigationDescriptor> navigationDescriptors,
|
||||
IEnumerable<IViewModelTemplateDescriptor> contentTemplateDescriptors)
|
||||
IViewModelTemplateDescriptorProvider contentTemplateDescriptors)
|
||||
{
|
||||
this.provider = provider;
|
||||
this.mediator = mediator;
|
||||
@@ -24,7 +24,7 @@ public class NavigateHandler :
|
||||
public async Task Handle(Navigate args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (contentTemplateDescriptors.FirstOrDefault(x => x.Key == args.Key)
|
||||
if (contentTemplateDescriptors.Get(args.Key)
|
||||
is IViewModelTemplateDescriptor contentTemplateDescriptor)
|
||||
{
|
||||
if (navigationDescriptors.FirstOrDefault(x => contentTemplateDescriptor.TemplateType == x.Type ||
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace Hyperbar;
|
||||
|
||||
public interface IViewModelTemplateFactory
|
||||
{
|
||||
object? Create(object key);
|
||||
}
|
||||
@@ -5,7 +5,7 @@ public class ViewModelTemplateDescriptorProvider(IEnumerable<IViewModelTemplateD
|
||||
{
|
||||
public IViewModelTemplateDescriptor? Get(object key)
|
||||
{
|
||||
if (descriptors.FirstOrDefault(x => x.Key == key)
|
||||
if (descriptors.FirstOrDefault(x => x.Key.Equals(key))
|
||||
is IViewModelTemplateDescriptor descriptor)
|
||||
{
|
||||
return descriptor;
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Hyperbar;
|
||||
|
||||
public class ViewModelTemplateFactory(IViewModelTemplateDescriptorProvider descriptors,
|
||||
IServiceProvider services) :
|
||||
IViewModelTemplateFactory
|
||||
{
|
||||
public object? Create(object key)
|
||||
{
|
||||
if (descriptors.Get(key)
|
||||
is IViewModelTemplateDescriptor descriptor)
|
||||
{
|
||||
if (services.GetRequiredKeyedService(descriptor.TemplateType,
|
||||
descriptor.Key) is { } template)
|
||||
{
|
||||
return template;
|
||||
}
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user