Wire up the disposer for cleaning up unused objects, i.e disposing a VM will remove it from the view

This commit is contained in:
TheXamlGuy
2024-01-12 21:05:42 +00:00
parent 814c806240
commit 2a773f26db
37 changed files with 323 additions and 206 deletions
+3 -1
View File
@@ -36,6 +36,8 @@ public partial class App :
new ServiceFactory((type, parameters) => ActivatorUtilities.CreateInstance(provider, type, parameters!)));
services.AddSingleton<IMediator, Mediator>();
services.AddSingleton<IDisposer, Disposer>();
services.AddHostedService<AppService>();
services.AddTransient<IInitializer, AppInitializer>();
@@ -45,7 +47,7 @@ public partial class App :
services.AddContentTemplate<WidgetBarViewModel, WidgetBarView>();
services.AddWidgetProvider<MediaControllerWidgetProvider>();
//services.AddWidgetProvider<MediaControllerWidgetProvider>();
services.AddWidgetProvider<PrimaryWidgetProvider>();
services.AddTransient(provider =>
+1
View File
@@ -30,6 +30,7 @@
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.231202003-experimental1" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.25936-preview" />
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
@@ -35,6 +35,7 @@ namespace Hyperbar.Windows
isolatedServices.AddTransient<ITemplateFactory, TemplateFactory>();
isolatedServices.AddSingleton<IMediator, Mediator>();
isolatedServices.AddSingleton<IDisposer, Disposer>();
isolatedServices.AddSingleton<IVirtualKeyboard, VirtualKeyboard>();
+2 -2
View File
@@ -17,8 +17,8 @@
Width="{StaticResource ButtonWidth}"
Height="{StaticResource ButtonHeight}"
Padding="{StaticResource ButtonPadding}"
FontSize="16"
Command="{Binding Click}"
Content="{Binding Icon}"
FontFamily="{StaticResource SymbolThemeFontFamily}" />
FontFamily="{StaticResource SymbolThemeFontFamily}"
FontSize="16" />
</UserControl>
+8
View File
@@ -3,12 +3,20 @@
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>
<interactivity:Interaction.Behaviors>
<interactions:EventTriggerBehavior EventName="Loaded">
<interactions:InvokeCommandAction Command="{Binding Initialize}" />
</interactions:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</ItemsControl>
</UserControl>
+1 -10
View File
@@ -1,5 +1,4 @@
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
namespace Hyperbar.Windows;
@@ -7,13 +6,5 @@ public sealed partial class WidgetView :
UserControl,
IWidgetView
{
public WidgetView()
{
InitializeComponent();
}
protected override void OnKeyDown(KeyRoutedEventArgs e)
{
base.OnKeyDown(e);
}
public WidgetView() => InitializeComponent();
}