More work
This commit is contained in:
+12
-12
@@ -2,30 +2,30 @@
|
||||
|
||||
namespace Hyperbar.Controls.Windows;
|
||||
|
||||
public class DesktopBar :
|
||||
public class DesktopApplicationBar :
|
||||
DependencyObject
|
||||
{
|
||||
public static readonly DependencyProperty ContentProperty =
|
||||
DependencyProperty.Register(nameof(Content),
|
||||
typeof(object), typeof(DesktopBar),
|
||||
typeof(object), typeof(DesktopApplicationBar),
|
||||
new PropertyMetadata(null));
|
||||
|
||||
public static readonly DependencyProperty PlacementProperty =
|
||||
DependencyProperty.Register(nameof(Placement),
|
||||
typeof(DesktopBarPlacemenet), typeof(DesktopBar),
|
||||
new PropertyMetadata(DesktopBarPlacemenet.Left, OnPlacementPropertyChanged));
|
||||
typeof(DesktopApplicationBarPlacemenet), typeof(DesktopApplicationBar),
|
||||
new PropertyMetadata(DesktopApplicationBarPlacemenet.Left, OnPlacementPropertyChanged));
|
||||
|
||||
private readonly DesktopBarHost host;
|
||||
private readonly DesktopBarPresenter presenter;
|
||||
private readonly DesktopApplicationBarHost host;
|
||||
private readonly DesktopApplicationBarPresenter presenter;
|
||||
|
||||
public DesktopBar()
|
||||
public DesktopApplicationBar()
|
||||
{
|
||||
presenter = new DesktopBarPresenter
|
||||
presenter = new DesktopApplicationBarPresenter
|
||||
{
|
||||
Parent = this
|
||||
};
|
||||
|
||||
host = new DesktopBarHost(presenter);
|
||||
host = new DesktopApplicationBarHost(presenter);
|
||||
host.Activate();
|
||||
}
|
||||
|
||||
@@ -35,16 +35,16 @@ public class DesktopBar :
|
||||
set => SetValue(ContentProperty, value);
|
||||
}
|
||||
|
||||
public DesktopBarPlacemenet Placement
|
||||
public DesktopApplicationBarPlacemenet Placement
|
||||
{
|
||||
get => (DesktopBarPlacemenet)GetValue(PlacementProperty);
|
||||
get => (DesktopApplicationBarPlacemenet)GetValue(PlacementProperty);
|
||||
set => SetValue(PlacementProperty, value);
|
||||
}
|
||||
|
||||
private static void OnPlacementPropertyChanged(DependencyObject dependencyObject,
|
||||
DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
if (dependencyObject is DesktopBar sender)
|
||||
if (dependencyObject is DesktopApplicationBar sender)
|
||||
{
|
||||
sender.OnPlacementPropertyChanged();
|
||||
}
|
||||
+9
-9
@@ -6,13 +6,13 @@ using Hyperbar.UI.Windows;
|
||||
|
||||
namespace Hyperbar.Controls.Windows;
|
||||
|
||||
internal class DesktopBarHost : Window
|
||||
internal class DesktopApplicationBarHost : Window
|
||||
{
|
||||
private readonly DesktopBarPresenter presenter;
|
||||
private readonly DesktopApplicationBarPresenter presenter;
|
||||
private readonly WindowSnapping windowSnapping;
|
||||
private DesktopBarPlacemenet placement;
|
||||
private DesktopApplicationBarPlacemenet placement;
|
||||
|
||||
public DesktopBarHost(DesktopBarPresenter presenter)
|
||||
public DesktopApplicationBarHost(DesktopApplicationBarPresenter presenter)
|
||||
{
|
||||
this.SetOpacity(0);
|
||||
this.SetStyle(WindowStyle.SysMenu | WindowStyle.Visible);
|
||||
@@ -31,7 +31,7 @@ internal class DesktopBarHost : Window
|
||||
Closed += OnClosed;
|
||||
}
|
||||
|
||||
internal void UpdatePlacement(DesktopBarPlacemenet placement)
|
||||
internal void UpdatePlacement(DesktopApplicationBarPlacemenet placement)
|
||||
{
|
||||
this.placement = placement;
|
||||
UpdatePlacement();
|
||||
@@ -44,19 +44,19 @@ internal class DesktopBarHost : Window
|
||||
|
||||
switch (placement)
|
||||
{
|
||||
case DesktopBarPlacemenet.Left:
|
||||
case DesktopApplicationBarPlacemenet.Left:
|
||||
windowSnapping.Snap(WindowSnappingPlacement.Left, (int)size);
|
||||
break;
|
||||
|
||||
case DesktopBarPlacemenet.Top:
|
||||
case DesktopApplicationBarPlacemenet.Top:
|
||||
windowSnapping.Snap(WindowSnappingPlacement.Top, (int)size);
|
||||
break;
|
||||
|
||||
case DesktopBarPlacemenet.Right:
|
||||
case DesktopApplicationBarPlacemenet.Right:
|
||||
windowSnapping.Snap(WindowSnappingPlacement.Right, (int)size);
|
||||
break;
|
||||
|
||||
case DesktopBarPlacemenet.Bottom:
|
||||
case DesktopApplicationBarPlacemenet.Bottom:
|
||||
windowSnapping.Snap(WindowSnappingPlacement.Bottom, (int)size);
|
||||
break;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
namespace Hyperbar.Controls.Windows;
|
||||
|
||||
public enum DesktopBarPlacemenet
|
||||
public enum DesktopApplicationBarPlacemenet
|
||||
{
|
||||
Left,
|
||||
Top,
|
||||
@@ -0,0 +1,40 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
|
||||
namespace Hyperbar.Controls.Windows;
|
||||
|
||||
public class DesktopApplicationBarPresenter :
|
||||
ContentControl
|
||||
{
|
||||
public static readonly DependencyProperty TemplateSettingsProperty =
|
||||
DependencyProperty.Register(nameof(TemplateSettings),
|
||||
typeof(DesktopApplicationBarPresenterTemplateSettings), typeof(DesktopApplicationBarPresenter),
|
||||
new PropertyMetadata(null));
|
||||
|
||||
internal new DesktopApplicationBar? Parent;
|
||||
|
||||
public DesktopApplicationBarPresenter()
|
||||
{
|
||||
DefaultStyleKey = typeof(DesktopApplicationBarPresenter);
|
||||
TemplateSettings = new DesktopApplicationBarPresenterTemplateSettings();
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate()
|
||||
{
|
||||
SetBinding(ContentProperty, new Binding
|
||||
{
|
||||
Source = Parent,
|
||||
Mode = BindingMode.TwoWay,
|
||||
Path = new PropertyPath(nameof(Parent.Content)),
|
||||
});
|
||||
}
|
||||
|
||||
public DesktopApplicationBarPresenterTemplateSettings TemplateSettings
|
||||
{
|
||||
get => (DesktopApplicationBarPresenterTemplateSettings)GetValue(TemplateSettingsProperty);
|
||||
set => SetValue(TemplateSettingsProperty, value);
|
||||
}
|
||||
|
||||
internal void UpdatePlacementState(DesktopApplicationBarPlacemenet placement) => VisualStateManager.GoToState(this, $"{placement}Placement", true);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:controls="using:Hyperbar.Controls.Windows">
|
||||
<ResourceDictionary.ThemeDictionaries>
|
||||
<ResourceDictionary x:Key="Default">
|
||||
<StaticResource x:Key="DesktopApplicationBarPresenterBackground" ResourceKey="AcrylicInAppFillColorDefaultBrush" />
|
||||
<StaticResource x:Key="DesktopApplicationBarPresenterForeground" ResourceKey="TextFillColorPrimaryBrush" />
|
||||
<StaticResource x:Key="DesktopApplicationBarPresenterBorderBrush" ResourceKey="ControlStrokeColorDefaultBrush" />
|
||||
</ResourceDictionary>
|
||||
<ResourceDictionary x:Key="Light">
|
||||
<StaticResource x:Key="DesktopApplicationBarPresenterBackground" ResourceKey="AcrylicInAppFillColorDefaultBrush" />
|
||||
<StaticResource x:Key="DesktopApplicationBarPresenterForeground" ResourceKey="TextFillColorPrimaryBrush" />
|
||||
<StaticResource x:Key="DesktopApplicationBarPresenterBorderBrush" ResourceKey="ControlStrokeColorDefaultBrush" />
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary.ThemeDictionaries>
|
||||
<Thickness x:Key="DesktopApplicationBarPresenterBorderThemeThickness">0</Thickness>
|
||||
<Style TargetType="controls:DesktopApplicationBarPresenter">
|
||||
<Setter Property="Foreground" Value="{ThemeResource DesktopApplicationBarPresenterForeground}" />
|
||||
<Setter Property="BorderBrush" Value="{ThemeResource DesktopApplicationBarPresenterBorderBrush}" />
|
||||
<Setter Property="BorderThickness" Value="{ThemeResource DesktopApplicationBarPresenterBorderThemeThickness}" />
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
|
||||
<Setter Property="VerticalContentAlignment" Value="Stretch" />
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch" />
|
||||
<Setter Property="VerticalAlignment" Value="Stretch" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="controls:DesktopApplicationBarPresenter">
|
||||
<Border
|
||||
MinHeight="48"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
||||
Background="{TemplateBinding Background}"
|
||||
BackgroundSizing="OuterBorderEdge"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="{TemplateBinding CornerRadius}"
|
||||
FlowDirection="{TemplateBinding FlowDirection}">
|
||||
<ContentControl
|
||||
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
||||
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
Content="{TemplateBinding Content}"
|
||||
ContentTemplate="{TemplateBinding ContentTemplate}"
|
||||
ContentTransitions="{TemplateBinding ContentTransitions}" />
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
+5
-5
@@ -2,26 +2,26 @@
|
||||
|
||||
namespace Hyperbar.Controls.Windows;
|
||||
|
||||
public class DesktopBarPresenterTemplateSettings : DependencyObject
|
||||
public class DesktopApplicationBarPresenterTemplateSettings : DependencyObject
|
||||
{
|
||||
public static readonly DependencyProperty HeightProperty =
|
||||
DependencyProperty.Register(nameof(Height),
|
||||
typeof(double), typeof(DesktopBarPresenterTemplateSettings),
|
||||
typeof(double), typeof(DesktopApplicationBarPresenterTemplateSettings),
|
||||
new PropertyMetadata(0d));
|
||||
|
||||
public static readonly DependencyProperty NegativeHeightProperty =
|
||||
DependencyProperty.Register(nameof(NegativeHeight),
|
||||
typeof(double), typeof(DesktopBarPresenterTemplateSettings),
|
||||
typeof(double), typeof(DesktopApplicationBarPresenterTemplateSettings),
|
||||
new PropertyMetadata(0d));
|
||||
|
||||
public static readonly DependencyProperty NegativeWidthProperty =
|
||||
DependencyProperty.Register(nameof(NegativeWidth),
|
||||
typeof(double), typeof(DesktopBarPresenterTemplateSettings),
|
||||
typeof(double), typeof(DesktopApplicationBarPresenterTemplateSettings),
|
||||
new PropertyMetadata(0d));
|
||||
|
||||
public static readonly DependencyProperty WidthProperty =
|
||||
DependencyProperty.Register(nameof(Width),
|
||||
typeof(double), typeof(DesktopBarPresenterTemplateSettings),
|
||||
typeof(double), typeof(DesktopApplicationBarPresenterTemplateSettings),
|
||||
new PropertyMetadata(0d));
|
||||
|
||||
public double Height
|
||||
@@ -1,40 +0,0 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
|
||||
namespace Hyperbar.Controls.Windows;
|
||||
|
||||
public class DesktopBarPresenter :
|
||||
ContentControl
|
||||
{
|
||||
public static readonly DependencyProperty TemplateSettingsProperty =
|
||||
DependencyProperty.Register(nameof(TemplateSettings),
|
||||
typeof(DesktopBarPresenterTemplateSettings), typeof(DesktopBarPresenter),
|
||||
new PropertyMetadata(null));
|
||||
|
||||
internal new DesktopBar? Parent;
|
||||
|
||||
public DesktopBarPresenter()
|
||||
{
|
||||
DefaultStyleKey = typeof(DesktopBarPresenter);
|
||||
TemplateSettings = new DesktopBarPresenterTemplateSettings();
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate()
|
||||
{
|
||||
SetBinding(ContentProperty, new Binding
|
||||
{
|
||||
Source = Parent,
|
||||
Mode = BindingMode.TwoWay,
|
||||
Path = new PropertyPath(nameof(Parent.Content)),
|
||||
});
|
||||
}
|
||||
|
||||
public DesktopBarPresenterTemplateSettings TemplateSettings
|
||||
{
|
||||
get => (DesktopBarPresenterTemplateSettings)GetValue(TemplateSettingsProperty);
|
||||
set => SetValue(TemplateSettingsProperty, value);
|
||||
}
|
||||
|
||||
internal void UpdatePlacementState(DesktopBarPlacemenet placement) => VisualStateManager.GoToState(this, $"{placement}Placement", true);
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:controls="using:Hyperbar.Controls.Windows">
|
||||
<ResourceDictionary.ThemeDictionaries>
|
||||
<ResourceDictionary x:Key="Default">
|
||||
<StaticResource x:Key="DesktopBarPresenterBackground" ResourceKey="AcrylicInAppFillColorDefaultBrush" />
|
||||
<StaticResource x:Key="DesktopBarPresenterForeground" ResourceKey="TextFillColorPrimaryBrush" />
|
||||
<StaticResource x:Key="DesktopBarPresenterBorderBrush" ResourceKey="ControlStrokeColorDefaultBrush" />
|
||||
</ResourceDictionary>
|
||||
<ResourceDictionary x:Key="Light">
|
||||
<StaticResource x:Key="DesktopBarPresenterBackground" ResourceKey="AcrylicInAppFillColorDefaultBrush" />
|
||||
<StaticResource x:Key="DesktopBarPresenterForeground" ResourceKey="TextFillColorPrimaryBrush" />
|
||||
<StaticResource x:Key="DesktopBarPresenterBorderBrush" ResourceKey="ControlStrokeColorDefaultBrush" />
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary.ThemeDictionaries>
|
||||
<Thickness x:Key="DesktopBarPresenterBorderThemeThickness">0</Thickness>
|
||||
<Style TargetType="controls:DesktopBarPresenter">
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="Foreground" Value="{ThemeResource DesktopBarPresenterForeground}" />
|
||||
<Setter Property="BorderBrush" Value="{ThemeResource DesktopBarPresenterBorderBrush}" />
|
||||
<Setter Property="BorderThickness" Value="{ThemeResource DesktopBarPresenterBorderThemeThickness}" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="controls:DesktopBarPresenter">
|
||||
<Border x:Name="Container" Background="Transparent">
|
||||
<Border
|
||||
x:Name="BackgroundElement"
|
||||
MinWidth="48"
|
||||
MinHeight="48"
|
||||
Background="{TemplateBinding Background}"
|
||||
BackgroundSizing="OuterBorderEdge"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="{TemplateBinding CornerRadius}"
|
||||
FlowDirection="{TemplateBinding FlowDirection}">
|
||||
<ContentControl
|
||||
Height="40"
|
||||
Margin="4"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
Content="{TemplateBinding Content}"
|
||||
ContentTemplate="{TemplateBinding ContentTemplate}"
|
||||
ContentTransitions="{TemplateBinding ContentTransitions}" />
|
||||
</Border>
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup x:Name="PlacementStates">
|
||||
<VisualState x:Name="DefaultPlacement" />
|
||||
<VisualState x:Name="BottomPlacement" />
|
||||
<VisualState x:Name="TopPlacement" />
|
||||
<VisualState x:Name="LeftPlacement" />
|
||||
<VisualState x:Name="RightPlacement" />
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="ms-appx:///Hyperbar.Controls.Windows/DesktopBar/DesktopBarPresenter.xaml" />
|
||||
<ResourceDictionary Source="ms-appx:///Hyperbar.Controls.Windows/DesktopApplicationBar/DesktopApplicationBarPresenter.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
@@ -0,0 +1,46 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
|
||||
namespace Hyperbar.UI.Windows;
|
||||
|
||||
public class GridExtension
|
||||
{
|
||||
public static readonly DependencyProperty GridColumnBindingPathProperty =
|
||||
DependencyProperty.RegisterAttached("GridColumnBindingPath",
|
||||
typeof(string), typeof(GridExtension),
|
||||
new PropertyMetadata(null, OnGridBindingPathPropertyChanged));
|
||||
|
||||
public static readonly DependencyProperty GridRowBindingPathProperty =
|
||||
DependencyProperty.RegisterAttached("GridRowBindingPath",
|
||||
typeof(string), typeof(GridExtension),
|
||||
new PropertyMetadata(null, OnGridBindingPathPropertyChanged));
|
||||
|
||||
public static string GetGridColumnBindingPath(DependencyObject dependencyObject) =>
|
||||
(string)dependencyObject.GetValue(GridColumnBindingPathProperty);
|
||||
|
||||
public static string GetGridRowBindingPath(DependencyObject dependencyObject) =>
|
||||
(string)dependencyObject.GetValue(GridRowBindingPathProperty);
|
||||
|
||||
public static void SetGridColumnBindingPath(DependencyObject dependencyObject, string value) =>
|
||||
dependencyObject.SetValue(GridColumnBindingPathProperty, value);
|
||||
public static void SetGridRowBindingPath(DependencyObject dependencyObject, string value) =>
|
||||
dependencyObject.SetValue(GridRowBindingPathProperty, value);
|
||||
|
||||
private static void OnGridBindingPathPropertyChanged(DependencyObject dependencyObject,
|
||||
DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
if (args.NewValue is string propertyPath)
|
||||
{
|
||||
DependencyProperty gridProperty =
|
||||
args.Property == GridColumnBindingPathProperty
|
||||
? Grid.ColumnProperty
|
||||
: Grid.RowProperty;
|
||||
|
||||
BindingOperations.SetBinding(
|
||||
dependencyObject,
|
||||
gridProperty,
|
||||
new Binding { Path = new PropertyPath(propertyPath) });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,12 +11,10 @@ public class TemplateGenerator : DataTemplateSelector
|
||||
string xamlString = @"
|
||||
<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
|
||||
xmlns:ui=""using:Hyperbar.UI.Windows"">
|
||||
<Grid>
|
||||
<ui:TemplateGeneratorControl VerticalContentAlignment=""Stretch""
|
||||
HorizontalContentAlignment=""Stretch""
|
||||
HorizontalAlignment=""Stretch""
|
||||
VerticalAlignment=""Stretch""/>
|
||||
</Grid>
|
||||
<ui:TemplateGeneratorControl VerticalContentAlignment=""Stretch""
|
||||
HorizontalContentAlignment=""Stretch""
|
||||
HorizontalAlignment=""Stretch""
|
||||
VerticalAlignment=""Stretch""/>
|
||||
</DataTemplate>";
|
||||
|
||||
return (DataTemplate)XamlReader.Load(xamlString);
|
||||
@@ -27,12 +25,10 @@ public class TemplateGenerator : DataTemplateSelector
|
||||
string xamlString = @"
|
||||
<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
|
||||
xmlns:ui=""using:Hyperbar.UI.Windows"">
|
||||
<Grid>
|
||||
<ui:TemplateGeneratorControl VerticalContentAlignment=""Stretch""
|
||||
HorizontalContentAlignment=""Stretch""
|
||||
HorizontalAlignment=""Stretch""
|
||||
VerticalAlignment=""Stretch""/>
|
||||
</Grid>
|
||||
<ui:TemplateGeneratorControl VerticalContentAlignment=""Stretch""
|
||||
HorizontalContentAlignment=""Stretch""
|
||||
HorizontalAlignment=""Stretch""
|
||||
VerticalAlignment=""Stretch""/>
|
||||
</DataTemplate>";
|
||||
|
||||
return (DataTemplate)XamlReader.Load(xamlString);
|
||||
|
||||
@@ -11,7 +11,8 @@ public class TemplateGeneratorControl :
|
||||
DataContextChanged += OnDataContextChanged;
|
||||
}
|
||||
|
||||
private void OnDataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
|
||||
private void OnDataContextChanged(FrameworkElement sender,
|
||||
DataContextChangedEventArgs args)
|
||||
{
|
||||
if (DataContext is ITemplatedViewModel templatedViewModel)
|
||||
{
|
||||
|
||||
@@ -10,8 +10,6 @@ public static class IServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddWidgetWindows(this IServiceCollection services)
|
||||
{
|
||||
services.AddContentTemplate<WidgetViewModel, WidgetBarView>();
|
||||
|
||||
// We need to feed information to the Widgets about our Windows host,
|
||||
// so the Windows host can make discussions how to display and interact with the widgets.
|
||||
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace Hyperbar.Widget.Windows;
|
||||
|
||||
public sealed partial class WidgetBarView :
|
||||
UserControl
|
||||
{
|
||||
public WidgetBarView() => InitializeComponent();
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public interface IWidgetHostViewModel;
|
||||
@@ -1,12 +0,0 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
[NotificationHandler(nameof(WidgetViewModel))]
|
||||
public partial class WidgetViewModel(ITemplateFactory templateFactory,
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer) :
|
||||
ObservableCollectionViewModel<IWidgetViewModel>(serviceFactory, mediator, disposer),
|
||||
ITemplatedViewModel
|
||||
{
|
||||
public ITemplateFactory TemplateFactory => templateFactory;
|
||||
}
|
||||
@@ -13,7 +13,7 @@ public class WidgetStartedHandler(IMediator mediator) :
|
||||
if (host.Services.GetService<IWidgetViewModel>() is IWidgetViewModel viewModel)
|
||||
{
|
||||
await mediator.PublishAsync(new Created<IWidgetViewModel>(viewModel),
|
||||
nameof(WidgetViewModel), cancellationToken);
|
||||
nameof(IWidgetHostViewModel), cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public class WidgetViewModelEnumerator(IWidgetHost host,
|
||||
foreach (IWidgetViewModel viewModel in viewModels)
|
||||
{
|
||||
await mediator.PublishAsync(new Created<IWidgetViewModel>(viewModel),
|
||||
nameof(WidgetViewModel), cancellationToken);
|
||||
nameof(IWidgetHostViewModel), cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,11 +43,15 @@ public partial class App :
|
||||
services.AddHandler<AppConfigurationChangedHandler>();
|
||||
services.AddConfiguration<AppConfiguration>(args =>
|
||||
{
|
||||
args.Placement = DesktopBarPlacemenet.Top;
|
||||
args.Placement = DesktopApplicationBarPlacemenet.Top;
|
||||
});
|
||||
|
||||
services.AddSingleton<DesktopApplicationBar>();
|
||||
services.AddContentTemplate<ApplicationBarViewModel, ApplicationBarView>();
|
||||
services.AddContentTemplate<PrimaryViewModel, PrimaryView>();
|
||||
services.AddContentTemplate<SecondaryViewModel, SecondaryView>();
|
||||
|
||||
services.AddTransient<IInitializer, AppInitializer>();
|
||||
services.AddSingleton<DesktopBar>();
|
||||
})
|
||||
.Build();
|
||||
|
||||
|
||||
+1
-1
@@ -4,5 +4,5 @@ namespace Hyperbar.Windows;
|
||||
|
||||
public class AppConfiguration
|
||||
{
|
||||
public DesktopBarPlacemenet Placement { get; set; }
|
||||
public DesktopApplicationBarPlacemenet Placement { get; set; }
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
using Hyperbar.Controls.Windows;
|
||||
using Hyperbar.Widget;
|
||||
using Hyperbar.Widget.Windows;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Hyperbar.Windows;
|
||||
|
||||
public class AppInitializer([FromKeyedServices(nameof(WidgetViewModel))] WidgetBarView view,
|
||||
[FromKeyedServices(nameof(WidgetViewModel))] WidgetViewModel viewModel,
|
||||
DesktopBar desktopFlyout,
|
||||
public class AppInitializer([FromKeyedServices(nameof(ApplicationBarViewModel))] ApplicationBarView view,
|
||||
[FromKeyedServices(nameof(ApplicationBarViewModel))] ApplicationBarViewModel viewModel,
|
||||
DesktopApplicationBar desktopFlyout,
|
||||
AppConfiguration configuration) :
|
||||
IInitializer
|
||||
{
|
||||
+12
-2
@@ -1,13 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<UserControl
|
||||
x:Class="Hyperbar.Widget.Windows.WidgetBarView"
|
||||
x:Class="Hyperbar.Windows.ApplicationBarView"
|
||||
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 ItemTemplateSelector="{Binding Converter={windows:DataTemplateConverter}}" ItemsSource="{Binding}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<StackPanel Orientation="Horizontal" />
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="400" />
|
||||
</Grid.ColumnDefinitions>
|
||||
</Grid>
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemContainerTransitions>
|
||||
@@ -15,5 +20,10 @@
|
||||
<AddDeleteThemeTransition />
|
||||
</TransitionCollection>
|
||||
</ItemsControl.ItemContainerTransitions>
|
||||
<ItemsControl.ItemContainerStyle>
|
||||
<Style TargetType="ContentPresenter">
|
||||
<Setter Property="windows:GridExtension.GridColumnBindingPath" Value="Index" />
|
||||
</Style>
|
||||
</ItemsControl.ItemContainerStyle>
|
||||
</ItemsControl>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,9 @@
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace Hyperbar.Windows;
|
||||
|
||||
public sealed partial class ApplicationBarView :
|
||||
UserControl
|
||||
{
|
||||
public ApplicationBarView() => InitializeComponent();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
[NotificationHandler(nameof(IWidgetHostViewModel))]
|
||||
public partial class ApplicationBarViewModel :
|
||||
ObservableCollectionViewModel<IDisposable>,
|
||||
ITemplatedViewModel
|
||||
{
|
||||
public ApplicationBarViewModel(ITemplateFactory templateFactory,
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer) : base(serviceFactory, mediator, disposer)
|
||||
{
|
||||
TemplateFactory = templateFactory;
|
||||
|
||||
Add<PrimaryViewModel>(0);
|
||||
Add<SecondaryViewModel>(1);
|
||||
}
|
||||
|
||||
public ITemplateFactory TemplateFactory { get; }
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Hyperbar.Windows;
|
||||
|
||||
public class AppConfigurationChangedHandler(DesktopBar desktopFlyout,
|
||||
public class AppConfigurationChangedHandler(DesktopApplicationBar desktopFlyout,
|
||||
AppConfiguration configuration) :
|
||||
INotificationHandler<Changed<AppConfiguration>>
|
||||
{
|
||||
@@ -13,6 +13,11 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<UseRidGraph>true</UseRidGraph>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="ApplicationBarView.xaml" />
|
||||
<None Remove="PrimaryView.xaml" />
|
||||
<None Remove="SecondaryView.xaml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Assets\SplashScreen.scale-200.png" />
|
||||
<Content Include="Assets\LockScreenLogo.scale-200.png" />
|
||||
@@ -48,4 +53,20 @@
|
||||
<ProjectReference Include="..\Hyperbar.Widget\Hyperbar.Widget.csproj" />
|
||||
<ProjectReference Include="..\Hyperbar\Hyperbar.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Update="SecondaryView.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Update="PrimaryView.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Update="ApplicationBarView.xaml">
|
||||
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<UserControl
|
||||
x:Class="Hyperbar.Windows.PrimaryView"
|
||||
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>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,28 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Controls.Primitives;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
using Microsoft.UI.Xaml.Input;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Microsoft.UI.Xaml.Navigation;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
|
||||
// To learn more about WinUI, the WinUI project structure,
|
||||
// and more about our project templates, see: http://aka.ms/winui-project-info.
|
||||
|
||||
namespace Hyperbar.Windows
|
||||
{
|
||||
public sealed partial class PrimaryView : UserControl
|
||||
{
|
||||
public PrimaryView()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
[NotificationHandler(nameof(IWidgetHostViewModel))]
|
||||
public partial class PrimaryViewModel(ITemplateFactory templateFactory,
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
int index) :
|
||||
ObservableCollectionViewModel<IWidgetViewModel>(serviceFactory, mediator, disposer),
|
||||
IWidgetHostViewModel,
|
||||
ITemplatedViewModel
|
||||
{
|
||||
[ObservableProperty]
|
||||
private int index = index;
|
||||
|
||||
public ITemplateFactory TemplateFactory => templateFactory;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<UserControl
|
||||
x:Class="Hyperbar.Windows.SecondaryView"
|
||||
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>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,28 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Controls.Primitives;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
using Microsoft.UI.Xaml.Input;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Microsoft.UI.Xaml.Navigation;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
|
||||
// To learn more about WinUI, the WinUI project structure,
|
||||
// and more about our project templates, see: http://aka.ms/winui-project-info.
|
||||
|
||||
namespace Hyperbar.Windows
|
||||
{
|
||||
public sealed partial class SecondaryView : UserControl
|
||||
{
|
||||
public SecondaryView()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public partial class SecondaryViewModel(ITemplateFactory templateFactory,
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
int index) :
|
||||
ObservableCollectionViewModel<IDisposable>(serviceFactory, mediator, disposer),
|
||||
ITemplatedViewModel
|
||||
{
|
||||
[ObservableProperty]
|
||||
private int index = index;
|
||||
|
||||
public ITemplateFactory TemplateFactory => templateFactory;
|
||||
}
|
||||
Reference in New Issue
Block a user