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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ public partial class CommandViewModel :
|
||||
ITemplatedViewModel
|
||||
{
|
||||
public CommandViewModel(ITemplateFactory templateFactory,
|
||||
IEnumerable<ICommandWidgetViewModel> commands)
|
||||
IEnumerable<IWidgetViewModel> commands)
|
||||
{
|
||||
TemplateFactory = templateFactory;
|
||||
AddRange(commands);
|
||||
|
||||
@@ -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>
|
||||
@@ -0,0 +1,10 @@
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace Hyperbar.Windows;
|
||||
|
||||
public sealed partial class WidgetView :
|
||||
UserControl,
|
||||
IWidgetView
|
||||
{
|
||||
public WidgetView() => InitializeComponent();
|
||||
}
|
||||
Reference in New Issue
Block a user