Make custom widgets independent of any WinUI framework concerns. Although one can add WinUI concerns to ther widget if they want to build a fully customized widget. In theory, it may also be possible to host a widget of WPF, Avalonia, or Blazor.

This commit is contained in:
TheXamlGuy
2024-01-06 09:57:23 +00:00
parent 3e88950669
commit 4a27534e39
41 changed files with 218 additions and 205 deletions
+8 -10
View File
@@ -1,6 +1,4 @@
using Hyperbar.Windows.Contextual;
using Hyperbar.Windows.Controls;
using Hyperbar.Windows.Primary;
using Hyperbar.Windows.Controls;
using Hyperbar.Lifecycles;
using Hyperbar.Templates;
using Microsoft.Extensions.Configuration;
@@ -38,19 +36,19 @@ public partial class App :
services.AddTransient<ITemplateFactory, TemplateFactory>();
services.AddTransient<ITemplateGeneratorFactory, TemplateGeneratorFactory>();
services.AddDataTemplate<CommandViewModel, CommandView>();
services.AddContentTemplate<CommandViewModel, CommandView>();
services.AddCommand<ContextualCommandWidgetBuilder>("");
services.AddCommand<PrimaryCommandWidgetBuilder>("");
//services.AddCommand<ContextualCommandWidgetBuilder>("");
//services.AddWidget<PrimaryCommandWidgetBuilder>("");
services.AddTransient(provider =>
{
static IEnumerable<ICommandWidgetViewModel> Resolve(IServiceProvider services)
static IEnumerable<IWidgetViewModel> Resolve(IServiceProvider services)
{
foreach (ICommandWidgetContext commandContext in services.GetServices<ICommandWidgetContext>())
foreach (IWidgetContext commandContext in services.GetServices<IWidgetContext>())
{
if (commandContext.ServiceProvider.GetService<ICommandWidgetViewModel>() is
ICommandWidgetViewModel commandViewModel)
if (commandContext.ServiceProvider.GetService<IWidgetViewModel>() is
IWidgetViewModel commandViewModel)
{
yield return commandViewModel;
}
+2 -6
View File
@@ -14,10 +14,6 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<None Remove="ContextualCommandView.xaml" />
<None Remove="Views\CommandView.xaml" />
</ItemGroup>
<ItemGroup>
<Content Include="Assets\SplashScreen.scale-200.png" />
<Content Include="Assets\LockScreenLogo.scale-200.png" />
@@ -37,9 +33,9 @@
<ProjectCapability Include="Msix" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Hyperbar.Windows.Contextual\Hyperbar.Windows.Contextual.csproj" />
<ProjectReference Include="..\Hyperbar.Windows.Contextual\Hyperbar.Widget.Contextual.csproj" />
<ProjectReference Include="..\Hyperbar.Windows.Controls\Hyperbar.Windows.Controls.csproj" />
<ProjectReference Include="..\Hyperbar.Windows.Primary\Hyperbar.Windows.Primary.csproj" />
<ProjectReference Include="..\Hyperbar.Windows.Primary\Hyperbar.Widget.Primary.csproj" />
<ProjectReference Include="..\Hyperbar\Hyperbar.csproj" />
</ItemGroup>
<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
@@ -7,10 +7,10 @@ namespace Hyperbar.Windows
{
public static class IServiceCollectionExtensions
{
public static IServiceCollection AddCommand<TCommandBuilder>(this IServiceCollection services,
public static IServiceCollection AddWidget<TCommandBuilder>(this IServiceCollection services,
string key)
where TCommandBuilder :
ICommandWidgetBuilder, new()
IWidgetBuilder, new()
{
TCommandBuilder builder = new();
IHost? host = new HostBuilder()
@@ -22,7 +22,7 @@ namespace Hyperbar.Windows
builder.Create(isolatedServices);
}).Build();
services.AddTransient<ICommandWidgetContext>(provider => new CommandWidgetContext(host.Services));
services.AddTransient<IWidgetContext>(provider => new WidgetContext(host.Services));
return services;
}
}
@@ -9,7 +9,7 @@ using System.Linq;
namespace Hyperbar.Windows;
public class TemplateFactory(ITemplateGeneratorFactory factory,
IEnumerable<IDataTemplateDescriptor> descriptors,
IEnumerable<IContentTemplateDescriptor> descriptors,
IServiceProvider provider) :
DataTemplateSelector,
ITemplateFactory
@@ -20,7 +20,7 @@ public class TemplateFactory(ITemplateGeneratorFactory factory,
public object? Create(object key)
{
if (descriptors.FirstOrDefault(x => x.Key == key) is IDataTemplateDescriptor descriptor)
if (descriptors.FirstOrDefault(x => x.Key == key) is IContentTemplateDescriptor descriptor)
{
if (provider.GetRequiredKeyedService(descriptor.TemplateType, descriptor.Key) is { } template)
{
+2 -2
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<Page
<UserControl
x:Class="Hyperbar.Windows.CommandView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
@@ -10,4 +10,4 @@
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Page>
</UserControl>
+2 -1
View File
@@ -3,7 +3,8 @@ using Microsoft.UI.Xaml.Input;
namespace Hyperbar.Windows;
public sealed partial class CommandView : Page
public sealed partial class CommandView :
UserControl
{
public CommandView() => InitializeComponent();
+1 -1
View File
@@ -9,7 +9,7 @@ public partial class CommandViewModel :
ITemplatedViewModel
{
public CommandViewModel(ITemplateFactory templateFactory,
IEnumerable<ICommandWidgetViewModel> commands)
IEnumerable<IWidgetViewModel> commands)
{
TemplateFactory = templateFactory;
AddRange(commands);
+7
View File
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<UserControl
x:Class="Hyperbar.Windows.WidgetView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid />
</UserControl>
+10
View File
@@ -0,0 +1,10 @@
using Microsoft.UI.Xaml.Controls;
namespace Hyperbar.Windows;
public sealed partial class WidgetView :
UserControl,
IWidgetView
{
public WidgetView() => InitializeComponent();
}