Wire up secondary commands for settings etc

This commit is contained in:
TheXamlGuy
2024-02-04 15:06:17 +00:00
parent 731cf3cdf3
commit e0a630f82b
10 changed files with 85 additions and 24 deletions
@@ -19,11 +19,11 @@
</UserControl.Resources>
<Button
x:Name="Button"
Width="{StaticResource ButtonWidth}"
Height="{StaticResource ButtonHeight}"
Padding="{StaticResource ButtonPadding}"
Width="{ThemeResource ButtonWidth}"
Height="{ThemeResource ButtonHeight}"
Padding="{ThemeResource ButtonPadding}"
Command="{x:Bind ViewModel.InvokeCommand}"
FontFamily="{StaticResource SymbolThemeFontFamily}"
FontFamily="{ThemeResource SymbolThemeFontFamily}"
FontSize="16"
IsEnabled="False">
<interactivity:Interaction.Behaviors>
+2
View File
@@ -51,6 +51,8 @@ public partial class App :
services.AddContentTemplate<PrimaryViewModel, PrimaryView>();
services.AddContentTemplate<SecondaryViewModel, SecondaryView>();
services.AddContentTemplate<SettingsButtonViewModel, SettingsButtonView>();
services.AddTransient<IInitializer, AppInitializer>();
})
.Build();
+12 -1
View File
@@ -4,13 +4,24 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:windows="using:Hyperbar.UI.Windows">
<UserControl.Resources>
<SolidColorBrush x:Key="ButtonBackground" Color="Transparent" />
<SolidColorBrush x:Key="ButtonBorderBrush" Color="Transparent" />
<SolidColorBrush x:Key="ButtonBorderBrushPointerOver" Color="Transparent" />
<SolidColorBrush x:Key="ButtonBorderBrushPressed" Color="Transparent" />
<SolidColorBrush x:Key="ButtonBackgroundDisabled" Color="Transparent" />
<SolidColorBrush x:Key="ButtonBorderBrushDisabled" Color="Transparent" />
<Thickness x:Key="ButtonPadding">0</Thickness>
<x:Double x:Key="ButtonWidth">40</x:Double>
<x:Double x:Key="ButtonHeight">40</x:Double>
</UserControl.Resources>
<ItemsControl ItemTemplateSelector="{Binding Converter={windows:DataTemplateConverter}}" ItemsSource="{Binding}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="400" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
+6
View File
@@ -17,6 +17,7 @@
<None Remove="ApplicationBarView.xaml" />
<None Remove="PrimaryView.xaml" />
<None Remove="SecondaryView.xaml" />
<None Remove="SettingsButtonView.xaml" />
</ItemGroup>
<ItemGroup>
<Content Include="Assets\SplashScreen.scale-200.png" />
@@ -53,6 +54,11 @@
<ProjectReference Include="..\Hyperbar.Widget\Hyperbar.Widget.csproj" />
<ProjectReference Include="..\Hyperbar\Hyperbar.csproj" />
</ItemGroup>
<ItemGroup>
<Page Update="SettingsButtonView.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Page Update="SecondaryView.xaml">
<Generator>MSBuild:Compile</Generator>
+9 -10
View File
@@ -4,14 +4,13 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:windows="using:Hyperbar.UI.Windows">
<ItemsControl
HorizontalAlignment="Center"
ItemTemplateSelector="{Binding Converter={windows:DataTemplateConverter}}"
ItemsSource="{Binding}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<ItemsStackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<Grid Width="300" Background="red">
<ItemsControl ItemTemplateSelector="{Binding Converter={windows:DataTemplateConverter}}" ItemsSource="{Binding}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<ItemsStackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
</UserControl>
+17 -8
View File
@@ -1,17 +1,26 @@
using CommunityToolkit.Mvvm.ComponentModel;
using Hyperbar.Windows;
namespace Hyperbar.Widget;
public partial class SecondaryViewModel(ITemplateFactory templateFactory,
IServiceFactory serviceFactory,
IMediator mediator,
IDisposer disposer,
int index) :
ObservableCollectionViewModel<IDisposable>(serviceFactory, mediator, disposer),
public partial class SecondaryViewModel :
ObservableCollectionViewModel<IDisposable>,
ITemplatedViewModel
{
[ObservableProperty]
private int index = index;
private int index;
public ITemplateFactory TemplateFactory => templateFactory;
public SecondaryViewModel(ITemplateFactory templateFactory,
IServiceFactory serviceFactory,
IMediator mediator,
IDisposer disposer,
int index) : base(serviceFactory, mediator, disposer)
{
this.index = index;
this.TemplateFactory = templateFactory;
Add<SettingsButtonViewModel>();
}
public ITemplateFactory TemplateFactory { get; }
}
+7
View File
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<UserControl
x:Class="Hyperbar.Windows.SettingsButtonView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Button Content="dfffffff" />
</UserControl>
@@ -0,0 +1,10 @@
using Microsoft.UI.Xaml.Controls;
namespace Hyperbar.Windows;
public sealed partial class SettingsButtonView :
UserControl
{
public SettingsButtonView() =>
this.InitializeComponent();
}
@@ -0,0 +1,11 @@
namespace Hyperbar.Windows;
public class SettingsButtonViewModel(ITemplateFactory templateFactory,
IServiceFactory serviceFactory,
IMediator mediator,
IDisposer disposer) :
ObservableViewModel(serviceFactory, mediator, disposer),
ITemplatedViewModel
{
public ITemplateFactory TemplateFactory => templateFactory;
}
+7 -1
View File
@@ -2,9 +2,15 @@
namespace Hyperbar;
public class ObservableViewModel(IDisposer disposer) :
public class ObservableViewModel(IServiceFactory serviceFactory,
IMediator mediator,
IDisposer disposer) :
ObservableObject,
IDisposable
{
public IServiceFactory ServiceFactory => serviceFactory;
public IMediator Mediator => mediator;
public void Dispose() => disposer.Dispose(this);
}