too many to add
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Application
|
||||
x:Class="App1.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:App1">
|
||||
<Application.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
|
||||
<!-- Other merged dictionaries here -->
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
<!-- Other app resources here -->
|
||||
</ResourceDictionary>
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
@@ -0,0 +1,50 @@
|
||||
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 Microsoft.UI.Xaml.Shapes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using Windows.ApplicationModel;
|
||||
using Windows.ApplicationModel.Activation;
|
||||
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 App1
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides application-specific behavior to supplement the default Application class.
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes the singleton application object. This is the first line of authored code
|
||||
/// executed, and as such is the logical equivalent of main() or WinMain().
|
||||
/// </summary>
|
||||
public App()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when the application is launched.
|
||||
/// </summary>
|
||||
/// <param name="args">Details about the launch request and process.</param>
|
||||
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
|
||||
{
|
||||
m_window = new MainWindow();
|
||||
m_window.Activate();
|
||||
}
|
||||
|
||||
private Window m_window;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
|
||||
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
|
||||
<RootNamespace>App1</RootNamespace>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
<Platforms>x86;x64;ARM64</Platforms>
|
||||
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
|
||||
<PublishProfile>win10-$(Platform).pubxml</PublishProfile>
|
||||
<UseWinUI>true</UseWinUI>
|
||||
<EnableMsixTooling>true</EnableMsixTooling>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="Assets\SplashScreen.scale-200.png" />
|
||||
<Content Include="Assets\LockScreenLogo.scale-200.png" />
|
||||
<Content Include="Assets\Square150x150Logo.scale-200.png" />
|
||||
<Content Include="Assets\Square44x44Logo.scale-200.png" />
|
||||
<Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
|
||||
<Content Include="Assets\StoreLogo.png" />
|
||||
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.230913002" />
|
||||
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.755" />
|
||||
<Manifest Include="$(ApplicationManifest)" />
|
||||
</ItemGroup>
|
||||
|
||||
<!--
|
||||
Defining the "Msix" ProjectCapability here allows the Single-project MSIX Packaging
|
||||
Tools extension to be activated for this project even if the Windows App SDK Nuget
|
||||
package has not yet been restored.
|
||||
-->
|
||||
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
|
||||
<ProjectCapability Include="Msix"/>
|
||||
</ItemGroup>
|
||||
|
||||
<!--
|
||||
Defining the "HasPackageAndPublishMenuAddedByProject" property here allows the Solution
|
||||
Explorer "Package and Publish" context menu entry to be enabled for this project even if
|
||||
the Windows App SDK Nuget package has not yet been restored.
|
||||
-->
|
||||
<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
|
||||
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
After Width: | Height: | Size: 432 B |
|
After Width: | Height: | Size: 5.2 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 637 B |
|
After Width: | Height: | Size: 283 B |
|
After Width: | Height: | Size: 456 B |
|
After Width: | Height: | Size: 2.0 KiB |
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<Window
|
||||
x:Class="App1.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="using:App1"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<FlipView Width="400">
|
||||
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Green">
|
||||
<Grid>
|
||||
<ItemsControl>
|
||||
<Button />
|
||||
<Button />
|
||||
<Button />
|
||||
<Button />
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<StackPanel Orientation="Horizontal" Spacing="8" />
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
</ItemsControl>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid HorizontalAlignment="Right" Background="Green">
|
||||
<Grid>
|
||||
<ItemsControl>
|
||||
<Button />
|
||||
<Button />
|
||||
<Button />
|
||||
<Button />
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<StackPanel Orientation="Horizontal" Spacing="8" />
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
</ItemsControl>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</FlipView>
|
||||
</Window>
|
||||
@@ -0,0 +1,31 @@
|
||||
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 App1
|
||||
{
|
||||
/// <summary>
|
||||
/// An empty window that can be used on its own or navigated to within a Frame.
|
||||
/// </summary>
|
||||
public sealed partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<Package
|
||||
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
|
||||
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
|
||||
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
|
||||
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
|
||||
IgnorableNamespaces="uap rescap">
|
||||
|
||||
<Identity
|
||||
Name="f69ee404-ac85-43ce-8664-73aeecf48925"
|
||||
Publisher="CN=dan_c"
|
||||
Version="1.0.0.0" />
|
||||
|
||||
<mp:PhoneIdentity PhoneProductId="f69ee404-ac85-43ce-8664-73aeecf48925" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
|
||||
|
||||
<Properties>
|
||||
<DisplayName>App1</DisplayName>
|
||||
<PublisherDisplayName>dan_c</PublisherDisplayName>
|
||||
<Logo>Assets\StoreLogo.png</Logo>
|
||||
</Properties>
|
||||
|
||||
<Dependencies>
|
||||
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
|
||||
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
|
||||
</Dependencies>
|
||||
|
||||
<Resources>
|
||||
<Resource Language="x-generate"/>
|
||||
</Resources>
|
||||
|
||||
<Applications>
|
||||
<Application Id="App"
|
||||
Executable="$targetnametoken$.exe"
|
||||
EntryPoint="$targetentrypoint$">
|
||||
<uap:VisualElements
|
||||
DisplayName="App1"
|
||||
Description="App1"
|
||||
BackgroundColor="transparent"
|
||||
Square150x150Logo="Assets\Square150x150Logo.png"
|
||||
Square44x44Logo="Assets\Square44x44Logo.png">
|
||||
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" />
|
||||
<uap:SplashScreen Image="Assets\SplashScreen.png" />
|
||||
</uap:VisualElements>
|
||||
</Application>
|
||||
</Applications>
|
||||
|
||||
<Capabilities>
|
||||
<rescap:Capability Name="runFullTrust" />
|
||||
</Capabilities>
|
||||
</Package>
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"profiles": {
|
||||
"App1 (Package)": {
|
||||
"commandName": "MsixPackage"
|
||||
},
|
||||
"App1 (Unpackaged)": {
|
||||
"commandName": "Project"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<assemblyIdentity version="1.0.0.0" name="App1.app"/>
|
||||
|
||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||
<application>
|
||||
<!-- The ID below informs the system that this application is compatible with OS features first introduced in Windows 10.
|
||||
It is necessary to support features in unpackaged applications, for example the custom titlebar implementation.
|
||||
For more info see https://docs.microsoft.com/windows/apps/windows-app-sdk/use-windows-app-sdk-run-time#declare-os-compatibility-in-your-application-manifest -->
|
||||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
|
||||
</application>
|
||||
</compatibility>
|
||||
|
||||
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<windowsSettings>
|
||||
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
|
||||
</windowsSettings>
|
||||
</application>
|
||||
</assembly>
|
||||
@@ -12,4 +12,4 @@ public class DataTemplateConverter :
|
||||
{
|
||||
return new TemplateGenerator();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Microsoft.UI.Xaml.Media.Imaging;
|
||||
using Windows.Storage.Streams;
|
||||
|
||||
namespace Hyperbar.UI.Windows;
|
||||
|
||||
public class StreamToImageSourceConverter :
|
||||
ValueConverter<Stream, ImageSource>
|
||||
{
|
||||
protected override ImageSource? ConvertTo(Stream value,
|
||||
Type? targetType,
|
||||
object? parameter,
|
||||
string? language)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
IRandomAccessStream randomAccessStream =
|
||||
WindowsRuntimeStreamExtensions.AsRandomAccessStream(value);
|
||||
|
||||
BitmapImage bitmapImage = new();
|
||||
bitmapImage.SetSource(randomAccessStream);
|
||||
return bitmapImage;
|
||||
}
|
||||
}
|
||||
@@ -9,9 +9,14 @@ public class TemplateGenerator : DataTemplateSelector
|
||||
protected override DataTemplate SelectTemplateCore(object item)
|
||||
{
|
||||
string xamlString = @"
|
||||
<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
|
||||
xmlns:ui='using:Hyperbar.UI.Windows'>
|
||||
<ui:TemplateGeneratorControl />
|
||||
<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>
|
||||
</DataTemplate>";
|
||||
|
||||
return (DataTemplate)XamlReader.Load(xamlString);
|
||||
@@ -20,9 +25,14 @@ public class TemplateGenerator : DataTemplateSelector
|
||||
protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
|
||||
{
|
||||
string xamlString = @"
|
||||
<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
|
||||
xmlns:ui='using:Hyperbar.UI.Windows'>
|
||||
<ui:TemplateGeneratorControl />
|
||||
<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>
|
||||
</DataTemplate>";
|
||||
|
||||
return (DataTemplate)XamlReader.Load(xamlString);
|
||||
|
||||
@@ -17,9 +17,5 @@ public class TemplateGeneratorControl :
|
||||
{
|
||||
Content = templatedViewModel.TemplateFactory.Create(DataContext.GetType().Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,7 @@
|
||||
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"
|
||||
Visibility="{x:Bind ViewModel.Visible, Mode=OneWay}">
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity">
|
||||
<UserControl.Resources>
|
||||
<SolidColorBrush x:Key="ButtonBackground" Color="Transparent" />
|
||||
<SolidColorBrush x:Key="ButtonBorderBrush" Color="Transparent" />
|
||||
|
||||
@@ -1,39 +1,43 @@
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace Hyperbar.Widget.MediaController.Windows;
|
||||
|
||||
public class MediaButtonViewModel(IServiceFactory serviceFactory,
|
||||
[NotificationHandler(nameof(PlaybackButtonType))]
|
||||
public partial class MediaButtonViewModel(IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
ITemplateFactory templateFactory,
|
||||
PlaybackButtonType buttonType,
|
||||
PlaybackButtonType playbackButtonType,
|
||||
Guid guid = default,
|
||||
string? text = null,
|
||||
string? icon = null,
|
||||
RelayCommand? command = null) :
|
||||
WidgetButtonViewModel(serviceFactory, mediator, disposer, templateFactory, guid, text, icon, command),
|
||||
IInitialization,
|
||||
INotificationHandler<Changed<PlaybackInformation>>
|
||||
IInitialization
|
||||
{
|
||||
public Task Handle(Changed<PlaybackInformation> notification,
|
||||
[ObservableProperty]
|
||||
private PlaybackButtonType playbackButtonType = playbackButtonType;
|
||||
|
||||
public Task Handle(Changed<MediaControllerPlaybackStatus> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (notification.Value is PlaybackInformation information)
|
||||
if (notification.Value is MediaControllerPlaybackStatus information)
|
||||
{
|
||||
switch (buttonType)
|
||||
{
|
||||
case PlaybackButtonType.Play:
|
||||
Visible = information.Status is PlaybackStatus.Paused;
|
||||
break;
|
||||
case PlaybackButtonType.Pause:
|
||||
Visible = information.Status is PlaybackStatus.Playing;
|
||||
break;
|
||||
}
|
||||
//switch (buttonType)
|
||||
//{
|
||||
// case PlaybackButtonType.Play:
|
||||
// Visible = information.Status is PlaybackStatus.Paused;
|
||||
// break;
|
||||
// case PlaybackButtonType.Pause:
|
||||
// Visible = information.Status is PlaybackStatus.Playing;
|
||||
// break;
|
||||
//}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public override async Task InitializeAsync() =>
|
||||
await Mediator.PublishAsync<Request<PlaybackInformation>>();
|
||||
//public override async Task InitializeAsync() =>
|
||||
// await Mediator.PublishAsync<Request<PlaybackInformation>>();
|
||||
}
|
||||
|
||||
@@ -1,18 +1,25 @@
|
||||
using Windows.Media.Control;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Microsoft.UI.Xaml.Media.Imaging;
|
||||
using Windows.Graphics.Imaging;
|
||||
using Windows.Media.Control;
|
||||
using Windows.Storage.Streams;
|
||||
|
||||
namespace Hyperbar.Widget.MediaController.Windows;
|
||||
|
||||
public class MediaController :
|
||||
INotificationHandler<Play>,
|
||||
INotificationHandler<Pause>,
|
||||
INotificationHandler<Request<PlaybackInformation>>,
|
||||
INotificationHandler<Request<MediaControllerPlaybackStatus>>,
|
||||
INotificationHandler<Request<MediaInformation>>,
|
||||
IDisposable
|
||||
{
|
||||
private readonly AsyncLock asyncLock = new();
|
||||
private readonly IDisposer disposer;
|
||||
private readonly IMediator mediator;
|
||||
private readonly GlobalSystemMediaTransportControlsSession session;
|
||||
private GlobalSystemMediaTransportControlsSession? session;
|
||||
|
||||
private GlobalSystemMediaTransportControlsSessionPlaybackStatus playbackStatus;
|
||||
|
||||
public MediaController(IMediator mediator,
|
||||
IDisposer disposer,
|
||||
@@ -31,6 +38,8 @@ public class MediaController :
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
session = null;
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
disposer.Dispose(this);
|
||||
}
|
||||
@@ -49,7 +58,7 @@ public class MediaController :
|
||||
await UpdateMediaPlaybackPropertiesAsync();
|
||||
}
|
||||
|
||||
public async Task Handle(Request<PlaybackInformation> args,
|
||||
public async Task Handle(Request<MediaControllerPlaybackStatus> args,
|
||||
CancellationToken cancellationToken) => await UpdateMediaPlaybackPropertiesAsync();
|
||||
|
||||
public async Task Handle(Request<MediaInformation> args,
|
||||
@@ -68,9 +77,14 @@ public class MediaController :
|
||||
try
|
||||
{
|
||||
GlobalSystemMediaTransportControlsSessionPlaybackInfo playbackInfo = session.GetPlaybackInfo();
|
||||
await mediator.PublishAsync(new Changed<PlaybackInformation>(
|
||||
new PlaybackInformation((PlaybackStatus)playbackInfo.PlaybackStatus)));
|
||||
|
||||
if (playbackInfo.PlaybackStatus != playbackStatus)
|
||||
{
|
||||
playbackStatus = playbackInfo.PlaybackStatus;
|
||||
await mediator.PublishAsync(new Changed<MediaControllerPlaybackStatus>(
|
||||
new MediaControllerPlaybackStatus((PlaybackStatus)playbackStatus)));
|
||||
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -81,20 +95,31 @@ public class MediaController :
|
||||
|
||||
private async Task UpdateMediaPropertiesAsync()
|
||||
{
|
||||
using (await asyncLock)
|
||||
if (session is not null)
|
||||
{
|
||||
try
|
||||
using (await asyncLock)
|
||||
{
|
||||
GlobalSystemMediaTransportControlsSessionMediaProperties mediaProperties =
|
||||
await session.TryGetMediaPropertiesAsync();
|
||||
try
|
||||
{
|
||||
|
||||
await mediator.PublishAsync(new Changed<MediaInformation>(new MediaInformation(mediaProperties.Title,
|
||||
mediaProperties.Artist)));
|
||||
//
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
//InMemoryRandomAccessStream randomAccessStream = new InMemoryRandomAccessStream();
|
||||
|
||||
//// Copy the image stream to the random access stream
|
||||
//await d.AsStream().CopyToAsync(randomAccessStream.AsStreamForWrite());
|
||||
|
||||
GlobalSystemMediaTransportControlsSessionMediaProperties mediaProperties =
|
||||
await session.TryGetMediaPropertiesAsync();
|
||||
|
||||
IRandomAccessStreamWithContentType randomAccessStream = await mediaProperties.Thumbnail.OpenReadAsync();
|
||||
await mediator.PublishAsync(new Changed<MediaInformation>(new MediaInformation(mediaProperties.Title,
|
||||
mediaProperties.Artist, randomAccessStream.AsStream())));
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,10 @@
|
||||
namespace Hyperbar.Widget.MediaController.Windows;
|
||||
|
||||
public class MediaControllerManager(IMediator mediator,
|
||||
IFactory<GlobalSystemMediaTransportControlsSession, MediaController> factory,
|
||||
IDispatcher dispatcher,
|
||||
IDisposer disposer) :
|
||||
IFactory<GlobalSystemMediaTransportControlsSession, MediaController> factory) :
|
||||
IInitializer
|
||||
{
|
||||
|
||||
private readonly AsyncLock asyncLock = new();
|
||||
private readonly List<KeyValuePair<GlobalSystemMediaTransportControlsSession, MediaController>> cache = [];
|
||||
private GlobalSystemMediaTransportControlsSessionManager? mediaTransportControlsSessionManager;
|
||||
@@ -16,7 +15,7 @@ public class MediaControllerManager(IMediator mediator,
|
||||
{
|
||||
mediaTransportControlsSessionManager = await GlobalSystemMediaTransportControlsSessionManager.RequestAsync();
|
||||
mediaTransportControlsSessionManager.SessionsChanged += OnSessionsChanged;
|
||||
|
||||
|
||||
IReadOnlyList<GlobalSystemMediaTransportControlsSession> sessions =
|
||||
mediaTransportControlsSessionManager.GetSessions();
|
||||
|
||||
@@ -31,7 +30,8 @@ public class MediaControllerManager(IMediator mediator,
|
||||
if (factory.Create(session) is MediaController mediaController)
|
||||
{
|
||||
await mediator.PublishAsync(new Created<MediaController>(mediaController));
|
||||
cache.Add(new KeyValuePair<GlobalSystemMediaTransportControlsSession, MediaController>(session, mediaController));
|
||||
cache.Add(new KeyValuePair<GlobalSystemMediaTransportControlsSession, MediaController>(session,
|
||||
mediaController));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Hyperbar.Widget.MediaController.Windows;
|
||||
|
||||
public record PlaybackInformation(PlaybackStatus Status) :
|
||||
public record MediaControllerPlaybackStatus(PlaybackStatus Status) :
|
||||
INotification;
|
||||
@@ -0,0 +1,31 @@
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace Hyperbar.Widget.MediaController.Windows;
|
||||
|
||||
public class MediaControllerPlaybackStatusHandler(IMediator mediator,
|
||||
IServiceFactory factory) :
|
||||
INotificationHandler<Changed<MediaControllerPlaybackStatus>>
|
||||
{
|
||||
public async Task Handle(Changed<MediaControllerPlaybackStatus> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (notification.Value is MediaControllerPlaybackStatus mediaControllerPlaybackInformation)
|
||||
{
|
||||
if (mediaControllerPlaybackInformation.Status is PlaybackStatus.Playing)
|
||||
{
|
||||
await mediator.PublishAsync(new Replaced<WidgetComponentViewModel>(2, factory.Create<MediaButtonViewModel>(
|
||||
PlaybackButtonType.Pause, "Pause", "\uE769",
|
||||
new RelayCommand(async () => await mediator.PublishAsync<Pause>()))), nameof(MediaControllerViewModel),
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
if (mediaControllerPlaybackInformation.Status is PlaybackStatus.Paused)
|
||||
{
|
||||
await mediator.PublishAsync(new Replaced<WidgetComponentViewModel>(2, factory.Create<MediaButtonViewModel>(
|
||||
PlaybackButtonType.Pause, "Play", "\uE768",
|
||||
new RelayCommand(async () => await mediator.PublishAsync<Play>()))), nameof(MediaControllerViewModel),
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,12 @@
|
||||
x:Class="Hyperbar.Widget.MediaController.Windows.MediaControllerView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="using:Hyperbar.UI.Windows">
|
||||
<Grid Width="400" Background="red">
|
||||
xmlns:windows="using:Hyperbar.UI.Windows">
|
||||
<Grid>
|
||||
<ItemsControl
|
||||
HorizontalAlignment="Center"
|
||||
ItemTemplateSelector="{Binding Converter={ui:DataTemplateConverter}}"
|
||||
HorizontalAlignment="Right"
|
||||
HorizontalContentAlignment="Right"
|
||||
ItemTemplateSelector="{Binding Converter={windows:DataTemplateConverter}}"
|
||||
ItemsSource="{Binding}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Hyperbar.Widget.MediaController.Windows;
|
||||
|
||||
[NotificationHandler(nameof(MediaControllerViewModel))]
|
||||
public class MediaControllerViewModel :
|
||||
ObservableCollectionViewModel<WidgetComponentViewModel>,
|
||||
ITemplatedViewModel
|
||||
@@ -15,19 +16,15 @@ public class MediaControllerViewModel :
|
||||
|
||||
Add<MediaInformationViewModel>();
|
||||
|
||||
Add<MediaButtonViewModel>(PlaybackButtonType.Previous,
|
||||
Add<MediaButtonViewModel>(PlaybackButtonType.Previous,
|
||||
"Previous", "\uEB9E",
|
||||
new RelayCommand(async () => await mediator.PublishAsync<Previous>()));
|
||||
|
||||
Add<MediaButtonViewModel>(PlaybackButtonType.Play,
|
||||
"Play", "\uE768",
|
||||
new RelayCommand(async () => await mediator.PublishAsync<Play>()));
|
||||
|
||||
Add<MediaButtonViewModel>(PlaybackButtonType.Pause,
|
||||
"Pause", "\uE769",
|
||||
"Pause", "\uE769",
|
||||
new RelayCommand(async () => await mediator.PublishAsync<Pause>()));
|
||||
|
||||
Add<MediaButtonViewModel>(PlaybackButtonType.Forward,
|
||||
Add<MediaButtonViewModel>(PlaybackButtonType.Forward,
|
||||
"Forward", "\uEB9D",
|
||||
new RelayCommand(async () => await mediator.PublishAsync<Forward>()));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Hyperbar.Widget;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Windows.Media.Control;
|
||||
|
||||
@@ -22,6 +21,7 @@ public class MediaControllerWidget :
|
||||
.AddHandler<MediaControllerHandler>()
|
||||
.AddTransient<IFactory<MediaController, MediaControllerViewModel?>, MediaControllerViewModelFactory>()
|
||||
.AddCache<MediaController, MediaControllerViewModel>()
|
||||
.AddHandler<MediaControllerPlaybackStatusHandler>()
|
||||
.AddContentTemplate<MediaControllerViewModel, MediaControllerView>()
|
||||
.AddContentTemplate<MediaInformationViewModel, MediaInformationView>()
|
||||
.AddContentTemplate<MediaButtonViewModel, MediaButtonView>();
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
x:Class="Hyperbar.Widget.MediaController.Windows.MediaControllerWidgetView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="using:Hyperbar.UI.Windows">
|
||||
xmlns:windows="using:Hyperbar.UI.Windows">
|
||||
<FlipView
|
||||
x:Name="FlipView"
|
||||
Width="400"
|
||||
Background="Transparent"
|
||||
ItemTemplateSelector="{Binding Converter={ui:DataTemplateConverter}}"
|
||||
Width="360"
|
||||
ItemTemplateSelector="{Binding Converter={windows:DataTemplateConverter}}"
|
||||
ItemsSource="{Binding}" />
|
||||
</UserControl>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
namespace Hyperbar.Widget.MediaController.Windows;
|
||||
|
||||
public record MediaInformation(string Title, string Description);
|
||||
public record MediaInformation(string Title,
|
||||
string Description,
|
||||
Stream ThumbnailSource);
|
||||
|
||||
|
||||
|
||||
@@ -4,27 +4,35 @@
|
||||
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">
|
||||
<Grid>
|
||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
||||
xmlns:windows="using:Hyperbar.UI.Windows">
|
||||
<Grid Width="216">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="40" />
|
||||
<ColumnDefinition Width="8" />
|
||||
<ColumnDefinition Width="80" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Border
|
||||
Grid.Column="0"
|
||||
Width="40"
|
||||
Height="40"
|
||||
Background="Red" />
|
||||
Height="40">
|
||||
<Image Source="{Binding ThumbnailSource, Converter={windows:StreamToImageSourceConverter}}" />
|
||||
</Border>
|
||||
<StackPanel Grid.Column="2">
|
||||
<TextBlock Style="{ThemeResource BaseTextBlockStyle}" Text="{Binding Title}" />
|
||||
<TextBlock
|
||||
Style="{ThemeResource BaseTextBlockStyle}"
|
||||
Text="{x:Bind ViewModel.Title, Mode=OneWay}"
|
||||
TextTrimming="CharacterEllipsis"
|
||||
TextWrapping="NoWrap" />
|
||||
<TextBlock
|
||||
Opacity="0.7"
|
||||
Style="{ThemeResource CaptionTextBlockStyle}"
|
||||
Text="{Binding Description}" />
|
||||
Text="{x:Bind ViewModel.Description, Mode=OneWay}"
|
||||
TextTrimming="CharacterEllipsis"
|
||||
TextWrapping="NoWrap" />
|
||||
<interactivity:Interaction.Behaviors>
|
||||
<interactions:EventTriggerBehavior EventName="Loaded">
|
||||
<interactions:InvokeCommandAction Command="{Binding Initialize}" />
|
||||
<interactions:InvokeCommandAction Command="{x:Bind ViewModel.Initialize}" />
|
||||
</interactions:EventTriggerBehavior>
|
||||
</interactivity:Interaction.Behaviors>
|
||||
</StackPanel>
|
||||
|
||||
@@ -8,4 +8,6 @@ public sealed partial class MediaInformationView :
|
||||
{
|
||||
public MediaInformationView() =>
|
||||
this.InitializeComponent(ref _contentLoaded);
|
||||
|
||||
private MediaInformationViewModel ViewModel => (MediaInformationViewModel)DataContext;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Hyperbar.Widget;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
|
||||
namespace Hyperbar.Widget.MediaController.Windows;
|
||||
|
||||
@@ -14,6 +14,9 @@ public partial class MediaInformationViewModel(IServiceFactory serviceFactory,
|
||||
[ObservableProperty]
|
||||
private string? description;
|
||||
|
||||
[ObservableProperty]
|
||||
private Stream? thumbnailSource;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? title;
|
||||
|
||||
@@ -24,6 +27,7 @@ public partial class MediaInformationViewModel(IServiceFactory serviceFactory,
|
||||
{
|
||||
Title = value.Title;
|
||||
Description = value.Description;
|
||||
ThumbnailSource = value.ThumbnailSource;
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Hyperbar.Interop.Windows;
|
||||
using Hyperbar.UI.Windows;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.UI.Xaml.Markup;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Hyperbar.Widget.Windows;
|
||||
|
||||
@@ -16,6 +18,7 @@ public static class IServiceCollectionExtensions
|
||||
services.AddTransient<IProxyServiceCollection<IWidgetBuilder>>(provider =>
|
||||
new ProxyServiceCollection<IWidgetBuilder>(services =>
|
||||
{
|
||||
services.AddSingleton(provider.GetRequiredService<IList<IXamlMetadataProvider>>());
|
||||
services.AddSingleton(provider.GetRequiredService<IDispatcher>());
|
||||
services.AddTransient<IFactory<IWidgetHost, WidgetContainerViewModel?>,
|
||||
WidgetContainerFactory>();
|
||||
@@ -29,7 +32,8 @@ public static class IServiceCollectionExtensions
|
||||
services.AddHandler<WidgetViewModelEnumerator>();
|
||||
|
||||
services.AddTransient<IWidgetView, WidgetView>();
|
||||
services.AddTransient<IInitializer, WidgetResourceInitialization>();
|
||||
services.AddTransient<IInitializer, WidgetResourceInitializer>();
|
||||
services.AddTransient<IInitializer, WidgetXamlMetadataInitializer>();
|
||||
|
||||
services.AddContentTemplate<WidgetContainerViewModel, WidgetContainerView>();
|
||||
services.AddContentTemplate<WidgetButtonViewModel, WidgetButtonView>();
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
x:Class="Hyperbar.Widget.Windows.WidgetBarView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="using:Hyperbar.UI.Windows">
|
||||
<ItemsControl ItemTemplateSelector="{Binding Converter={ui:DataTemplateConverter}}" ItemsSource="{Binding}">
|
||||
xmlns:windows="using:Hyperbar.UI.Windows">
|
||||
<ItemsControl ItemTemplateSelector="{Binding Converter={windows:DataTemplateConverter}}" ItemsSource="{Binding}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<StackPanel Orientation="Horizontal" />
|
||||
|
||||
@@ -3,7 +3,7 @@ using Windows.Storage;
|
||||
|
||||
namespace Hyperbar.Widget.Windows;
|
||||
|
||||
internal class WidgetResourceInitialization(IWidgetAssembly widgetAssembly) :
|
||||
internal class WidgetResourceInitializer(IWidgetAssembly widgetAssembly) :
|
||||
IInitializer
|
||||
{
|
||||
public async Task InitializeAsync()
|
||||
@@ -5,9 +5,9 @@
|
||||
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.UI.Windows">
|
||||
xmlns:windows="using:Hyperbar.UI.Windows">
|
||||
<Grid>
|
||||
<ItemsControl ItemTemplateSelector="{Binding Converter={ui:DataTemplateConverter}}" ItemsSource="{Binding Mode=TwoWay}">
|
||||
<ItemsControl ItemTemplateSelector="{Binding Converter={windows:DataTemplateConverter}}" ItemsSource="{Binding Mode=TwoWay}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<StackPanel Orientation="Horizontal" Spacing="8" />
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using Microsoft.UI.Xaml.Markup;
|
||||
|
||||
namespace Hyperbar.Widget.Windows;
|
||||
|
||||
public class WidgetXamlMetadataInitializer(IWidgetAssembly widgetAssembly,
|
||||
IList<IXamlMetadataProvider> xamlMetadataProviders) :
|
||||
IInitializer
|
||||
{
|
||||
public Task InitializeAsync()
|
||||
{
|
||||
foreach (IXamlMetadataProvider xamlMetadataProvider in widgetAssembly.Assembly.ExportedTypes
|
||||
.Where(type => type.IsAssignableTo(typeof(IXamlMetadataProvider)))
|
||||
.Select(metadataType => (IXamlMetadataProvider)Activator.CreateInstance(metadataType)!))
|
||||
{
|
||||
xamlMetadataProviders.Add(xamlMetadataProvider);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using CustomExtensions.WinUI;
|
||||
using Hyperbar.Controls.Windows;
|
||||
using Hyperbar.Controls.Windows;
|
||||
using Hyperbar.UI.Windows;
|
||||
using Hyperbar.Widget;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
@@ -9,17 +8,14 @@ using Microsoft.UI.Dispatching;
|
||||
using Microsoft.UI.Xaml;
|
||||
using System.Reflection;
|
||||
using Hyperbar.Widget.Windows;
|
||||
using Microsoft.UI.Xaml.Markup;
|
||||
|
||||
namespace Hyperbar.Windows;
|
||||
|
||||
public partial class App :
|
||||
Application
|
||||
{
|
||||
public App()
|
||||
{
|
||||
InitializeComponent();
|
||||
ApplicationExtensionHost.Initialize(this);
|
||||
}
|
||||
public App() => InitializeComponent();
|
||||
|
||||
protected override async void OnLaunched(LaunchActivatedEventArgs args)
|
||||
{
|
||||
@@ -37,6 +33,7 @@ public partial class App :
|
||||
services.AddDefault();
|
||||
services.AddWidget();
|
||||
services.AddWidgetWindows();
|
||||
services.AddXamlMetadataProvider();
|
||||
|
||||
services.AddHostedService<AppService>();
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Markup;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public static class IServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddXamlMetadataProvider(this IServiceCollection services)
|
||||
{
|
||||
object? appProvider = Application.Current.GetType().GetProperty("_AppProvider", BindingFlags.NonPublic | BindingFlags.Instance)?
|
||||
.GetValue(Application.Current);
|
||||
|
||||
object? provider = appProvider?.GetType().GetProperty("Provider", BindingFlags.NonPublic | BindingFlags.Instance)?
|
||||
.GetValue(appProvider);
|
||||
|
||||
PropertyInfo? othersProviderProperty = provider?.GetType().GetProperty("OtherProviders", BindingFlags.NonPublic | BindingFlags.Instance,
|
||||
null, typeof(List<IXamlMetadataProvider>), [], null);
|
||||
|
||||
List<IXamlMetadataProvider> xamlMetadataProviders = othersProviderProperty?.GetValue(provider) as List<IXamlMetadataProvider> ?? [];
|
||||
|
||||
services.AddSingleton<IList<IXamlMetadataProvider>>(xamlMetadataProviders);
|
||||
return services;
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hyperbar.Widget.Primary.Win
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hyperbar.Widget.MediaController.Windows", "Hyperbar.Widget.MediaController.Windows\Hyperbar.Widget.MediaController.Windows.csproj", "{ACBB1C58-1DB6-40E1-ABF1-71F2D2F0EC73}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hyperbar.Widget.Windows", "Hyperbar.Widget.Windows\Hyperbar.Widget.Windows.csproj", "{E7322176-B67F-4A22-AFDB-7430A6AD44B6}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hyperbar.Widget.Windows", "Hyperbar.Widget.Windows\Hyperbar.Widget.Windows.csproj", "{E7322176-B67F-4A22-AFDB-7430A6AD44B6}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "App1", "App1\App1.csproj", "{AB161079-E1AA-4A9B-B64C-D27A68245A2C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -203,6 +205,30 @@ Global
|
||||
{E7322176-B67F-4A22-AFDB-7430A6AD44B6}.Release|x64.Build.0 = Release|Any CPU
|
||||
{E7322176-B67F-4A22-AFDB-7430A6AD44B6}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{E7322176-B67F-4A22-AFDB-7430A6AD44B6}.Release|x86.Build.0 = Release|Any CPU
|
||||
{AB161079-E1AA-4A9B-B64C-D27A68245A2C}.Debug|Any CPU.ActiveCfg = Debug|x64
|
||||
{AB161079-E1AA-4A9B-B64C-D27A68245A2C}.Debug|Any CPU.Build.0 = Debug|x64
|
||||
{AB161079-E1AA-4A9B-B64C-D27A68245A2C}.Debug|Any CPU.Deploy.0 = Debug|x64
|
||||
{AB161079-E1AA-4A9B-B64C-D27A68245A2C}.Debug|ARM64.ActiveCfg = Debug|ARM64
|
||||
{AB161079-E1AA-4A9B-B64C-D27A68245A2C}.Debug|ARM64.Build.0 = Debug|ARM64
|
||||
{AB161079-E1AA-4A9B-B64C-D27A68245A2C}.Debug|ARM64.Deploy.0 = Debug|ARM64
|
||||
{AB161079-E1AA-4A9B-B64C-D27A68245A2C}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{AB161079-E1AA-4A9B-B64C-D27A68245A2C}.Debug|x64.Build.0 = Debug|x64
|
||||
{AB161079-E1AA-4A9B-B64C-D27A68245A2C}.Debug|x64.Deploy.0 = Debug|x64
|
||||
{AB161079-E1AA-4A9B-B64C-D27A68245A2C}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{AB161079-E1AA-4A9B-B64C-D27A68245A2C}.Debug|x86.Build.0 = Debug|x86
|
||||
{AB161079-E1AA-4A9B-B64C-D27A68245A2C}.Debug|x86.Deploy.0 = Debug|x86
|
||||
{AB161079-E1AA-4A9B-B64C-D27A68245A2C}.Release|Any CPU.ActiveCfg = Release|x64
|
||||
{AB161079-E1AA-4A9B-B64C-D27A68245A2C}.Release|Any CPU.Build.0 = Release|x64
|
||||
{AB161079-E1AA-4A9B-B64C-D27A68245A2C}.Release|Any CPU.Deploy.0 = Release|x64
|
||||
{AB161079-E1AA-4A9B-B64C-D27A68245A2C}.Release|ARM64.ActiveCfg = Release|ARM64
|
||||
{AB161079-E1AA-4A9B-B64C-D27A68245A2C}.Release|ARM64.Build.0 = Release|ARM64
|
||||
{AB161079-E1AA-4A9B-B64C-D27A68245A2C}.Release|ARM64.Deploy.0 = Release|ARM64
|
||||
{AB161079-E1AA-4A9B-B64C-D27A68245A2C}.Release|x64.ActiveCfg = Release|x64
|
||||
{AB161079-E1AA-4A9B-B64C-D27A68245A2C}.Release|x64.Build.0 = Release|x64
|
||||
{AB161079-E1AA-4A9B-B64C-D27A68245A2C}.Release|x64.Deploy.0 = Release|x64
|
||||
{AB161079-E1AA-4A9B-B64C-D27A68245A2C}.Release|x86.ActiveCfg = Release|x86
|
||||
{AB161079-E1AA-4A9B-B64C-D27A68245A2C}.Release|x86.Build.0 = Release|x86
|
||||
{AB161079-E1AA-4A9B-B64C-D27A68245A2C}.Release|x86.Deploy.0 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -19,6 +19,7 @@ public partial class ObservableCollectionViewModel<TItem> :
|
||||
INotificationHandler<Created<TItem>>,
|
||||
INotificationHandler<Inserted<TItem>>,
|
||||
INotificationHandler<Moved<TItem>>,
|
||||
INotificationHandler<Replaced<TItem>>,
|
||||
IDisposable
|
||||
where TItem :
|
||||
IDisposable
|
||||
@@ -250,6 +251,17 @@ public partial class ObservableCollectionViewModel<TItem> :
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Handle(Replaced<TItem> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (notification.Value is TItem item)
|
||||
{
|
||||
Replace(notification.Index, item);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public int IndexOf(TItem item) =>
|
||||
collection.IndexOf(item);
|
||||
|
||||
@@ -272,6 +284,22 @@ public partial class ObservableCollectionViewModel<TItem> :
|
||||
}
|
||||
}
|
||||
|
||||
public bool Replace(int index, TItem item)
|
||||
{
|
||||
if (index <= Count - 1)
|
||||
{
|
||||
RemoveItem(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
index = Count;
|
||||
}
|
||||
|
||||
Insert(index, item);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Move(int index, TItem item)
|
||||
{
|
||||
int oldIndex = collection.IndexOf(item);
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
namespace Hyperbar;
|
||||
|
||||
public record Created<TValue>(TValue Value, object? Target = null) :
|
||||
INotification;
|
||||
INotification;
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
namespace Hyperbar;
|
||||
|
||||
public record Replaced<TValue>(int Index, TValue Value, object? Target = null) :
|
||||
INotification;
|
||||
|
||||