lots of tidying up

This commit is contained in:
TheXamlGuy
2024-01-25 20:33:55 +00:00
parent 5e26e97f6b
commit a322893166
20 changed files with 115 additions and 123 deletions
+13 -7
View File
@@ -6,6 +6,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml;
using System;
using System.Reflection;
@@ -21,7 +22,6 @@ public partial class App :
protected override async void OnLaunched(LaunchActivatedEventArgs args)
{
base.OnLaunched(args);
IHost? host = new HostBuilder()
.UseContentRoot(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
Assembly.GetEntryAssembly()?.GetName().Name!), true)
@@ -32,10 +32,10 @@ public partial class App :
.ConfigureServices((context, services) =>
{
services.AddDefault();
services.AddWidget();
services.AddHostedService<AppService>();
services.AddSingleton<IDispatcher, Dispatcher>();
services.AddSingleton<IDispatcher>(new Dispatcher(DispatcherQueue.GetForCurrentThread()));
services.AddTransient<ITemplateFactory, TemplateFactory>();
services.AddHandler<AppConfigurationChangedHandler>();
@@ -48,20 +48,26 @@ public partial class App :
services.AddSingleton<DesktopBar>();
services.AddContentTemplate<WidgetBarViewModel, WidgetBarView>();
services.AddContentTemplate<WidgetContainerViewModel, WidgetContainerView>();
services.AddTransient<IProxyServiceCollection<IWidgetBuilder>>(provider =>
new ProxyServiceCollection<IWidgetBuilder>(services =>
{
services.AddSingleton<IDispatcher, Dispatcher>();
services.AddTransient<ITemplateFactory, TemplateFactory>();
services.AddScoped<IVirtualKeyboard, VirtualKeyboard>();
services.AddSingleton<IDispatcher>(new Dispatcher(DispatcherQueue.GetForCurrentThread()));
services.AddTransient<IFactory<IWidgetHost, WidgetContainerViewModel?>,
WidgetContainerFactory>();
services.AddTransient<ITemplateFactory, TemplateFactory>();
services.AddScoped<IVirtualKeyboard, VirtualKeyboard>();
services.AddHandler<KeyAcceleratorHandler>();
services.AddHandler<StartProcessHandler>();
services.AddHandler<WidgetViewModelEnumerator>();
services.AddTransient<IWidgetView, WidgetView>();
services.AddContentTemplate<WidgetContainerViewModel, WidgetContainerView>();
services.AddContentTemplate<WidgetButtonViewModel, WidgetButtonView>();
services.AddContentTemplate<WidgetSplitButtonViewModel, WidgetSplitButtonView>();
}));
+3 -6
View File
@@ -3,12 +3,9 @@ using Microsoft.UI.Dispatching;
namespace Hyperbar.Windows;
public class Dispatcher :
public class Dispatcher(DispatcherQueue dispatcherQueue) :
IDispatcher
{
private DispatcherQueue dispatcherQueue;
public Dispatcher() => dispatcherQueue = DispatcherQueue.GetForCurrentThread();
public async Task InvokeAsync(Action action) => await dispatcherQueue.EnqueueAsync(action.Invoke);
public async Task InvokeAsync(Action action) =>
await dispatcherQueue.EnqueueAsync(action.Invoke);
}
@@ -3,6 +3,8 @@
x:Class="Hyperbar.Windows.WidgetContainerView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:interactions="using:Microsoft.Xaml.Interactions.Core"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:ui="using:Hyperbar.Windows.UI">
<Grid>
<Grid.ColumnDefinitions>
@@ -10,7 +12,7 @@
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Rectangle
Width="10"
Width="1"
Height="40"
Margin="6,2,6,2"
Fill="Red" />
@@ -23,6 +25,11 @@
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<interactivity:Interaction.Behaviors>
<interactions:EventTriggerBehavior EventName="Loaded">
<interactions:InvokeCommandAction Command="{Binding Initialize}" />
</interactions:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</ItemsControl>
</Grid>
</UserControl>
+21 -12
View File
@@ -3,17 +3,26 @@
x:Class="Hyperbar.Windows.WidgetView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:interactions="using:Microsoft.Xaml.Interactions.Core"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:ui="using:Hyperbar.Windows.UI">
<ItemsControl ItemTemplateSelector="{Binding Converter={ui:DataTemplateConverter}}" ItemsSource="{Binding}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Spacing="8" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerTransitions>
<TransitionCollection>
<AddDeleteThemeTransition />
</TransitionCollection>
</ItemsControl.ItemContainerTransitions>
</ItemsControl>
<Grid>
<ItemsControl ItemTemplateSelector="{Binding Converter={ui:DataTemplateConverter}}" ItemsSource="{Binding Mode=TwoWay}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Spacing="8" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerTransitions>
<TransitionCollection>
<AddDeleteThemeTransition />
</TransitionCollection>
</ItemsControl.ItemContainerTransitions>
<interactivity:Interaction.Behaviors>
<interactions:EventTriggerBehavior EventName="Loaded">
<interactions:InvokeCommandAction Command="{Binding Initialize}" />
</interactions:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</ItemsControl>
</Grid>
</UserControl>