wip
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Avalonia" Version="11.1.0-beta1" />
|
<PackageReference Include="Avalonia" Version="11.1.0-beta2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Toolkit.Foundation\Toolkit.Foundation.csproj" />
|
<ProjectReference Include="..\Toolkit.Foundation\Toolkit.Foundation.csproj" />
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
namespace Toolkit.Foundation;
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
public record Enumerate<TValue> : IEnumerate
|
public record Enumerate<TValue> :
|
||||||
|
IEnumerate
|
||||||
{
|
{
|
||||||
public object? Key { get; init; }
|
public object? Key { get; init; }
|
||||||
|
|
||||||
|
public EnumerateMode Mode { get; init; }
|
||||||
|
|
||||||
public static Enumerate<TValue, TOptions> With<TOptions>(TOptions options) where TOptions : class
|
public static Enumerate<TValue, TOptions> With<TOptions>(TOptions options) where TOptions : class
|
||||||
{
|
{
|
||||||
return new Enumerate<TValue, TOptions>(options);
|
return new Enumerate<TValue, TOptions>(options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IEnumerate
|
public record Enumerate<TValue, TOptions>(TOptions? Options = null) :
|
||||||
{
|
IEnumerate
|
||||||
object? Key { get; init; }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public record Enumerate<TValue, TOptions>(TOptions? Options = null) : IEnumerate
|
|
||||||
where TOptions : class
|
where TOptions : class
|
||||||
{
|
{
|
||||||
public object? Key { get; init; }
|
public object? Key { get; init; }
|
||||||
|
|
||||||
|
public EnumerateMode Mode { get; init; }
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
public enum EnumerateMode
|
||||||
|
{
|
||||||
|
Append,
|
||||||
|
Reset
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
public interface IEnumerate
|
||||||
|
{
|
||||||
|
object? Key { get; init; }
|
||||||
|
|
||||||
|
EnumerateMode Mode { get; init; }
|
||||||
|
}
|
||||||
@@ -1,7 +1,13 @@
|
|||||||
namespace Toolkit.Foundation;
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
|
[AttributeUsage(AttributeTargets.Class, Inherited = true)]
|
||||||
public class NotificationAttribute(object key) : Attribute
|
public class NotificationAttribute(object key) : Attribute
|
||||||
{
|
{
|
||||||
public object Key => key;
|
public object Key => key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class EnumerateAttribute(object key,
|
||||||
|
EnumerateMode mode = EnumerateMode.Reset) : NotificationAttribute(key)
|
||||||
|
{
|
||||||
|
public EnumerateMode Mode => mode;
|
||||||
}
|
}
|
||||||
@@ -310,17 +310,19 @@ public partial class ObservableCollectionViewModel<TViewModel> :
|
|||||||
|
|
||||||
public async Task Enumerate()
|
public async Task Enumerate()
|
||||||
{
|
{
|
||||||
Clear();
|
if (this.GetAttribute<EnumerateAttribute>() is EnumerateAttribute attribute)
|
||||||
|
{
|
||||||
|
if (attribute.Mode == EnumerateMode.Reset)
|
||||||
|
{
|
||||||
|
Clear();
|
||||||
|
}
|
||||||
|
|
||||||
object? key = this.GetAttribute<NotificationAttribute>()
|
object? key = this.GetPropertyValue(() => attribute.Key) is { } value ? value : attribute.Key;
|
||||||
is NotificationAttribute attribute
|
await Publisher.PublishUI(PrepareEnumeration(key));
|
||||||
? this.GetPropertyValue(() => attribute.Key) is { } value ? value : attribute.Key
|
}
|
||||||
: null;
|
|
||||||
|
|
||||||
await Publisher.PublishUI(CreateEnumeration(key));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual IEnumerate CreateEnumeration(object? key) =>
|
protected virtual IEnumerate PrepareEnumeration(object? key) =>
|
||||||
new Enumerate<TViewModel>() with { Key = key };
|
new Enumerate<TViewModel>() with { Key = key };
|
||||||
|
|
||||||
public void Insert(int index, TViewModel item) =>
|
public void Insert(int index, TViewModel item) =>
|
||||||
|
|||||||
@@ -73,4 +73,16 @@ public partial class ObservableViewModel :
|
|||||||
IsInitialized = true;
|
IsInitialized = true;
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public partial class ObservableViewModel<TValue>(IServiceProvider provider,
|
||||||
|
IServiceFactory factory,
|
||||||
|
IMediator mediator,
|
||||||
|
IPublisher publisher,
|
||||||
|
ISubscriber subscriber,
|
||||||
|
IDisposer disposer) : ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer)
|
||||||
|
where TValue : notnull
|
||||||
|
{
|
||||||
|
[ObservableProperty]
|
||||||
|
private TValue? value;
|
||||||
}
|
}
|
||||||
@@ -54,7 +54,17 @@ public class SubscriptionManager(SubscriptionCollection subscriptions) :
|
|||||||
{
|
{
|
||||||
if (interfaceType.GetGenericArguments().FirstOrDefault() is Type argumentType)
|
if (interfaceType.GetGenericArguments().FirstOrDefault() is Type argumentType)
|
||||||
{
|
{
|
||||||
subscriptions.AddOrUpdate($"{(key is not null ? $"{key}:" : "")}{argumentType}", _ => new List<WeakReference> { new(subscriber) }, (_, collection) =>
|
if (key is not null)
|
||||||
|
{
|
||||||
|
subscriptions.AddOrUpdate($"{key}:{argumentType}", _ => new List<WeakReference> { new(subscriber) }, (_, collection) =>
|
||||||
|
{
|
||||||
|
collection.Add(new WeakReference(subscriber));
|
||||||
|
return collection;
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
subscriptions.AddOrUpdate($"{argumentType}", _ => new List<WeakReference> { new(subscriber) }, (_, collection) =>
|
||||||
{
|
{
|
||||||
collection.Add(new WeakReference(subscriber));
|
collection.Add(new WeakReference(subscriber));
|
||||||
return collection;
|
return collection;
|
||||||
|
|||||||
@@ -1,10 +1,86 @@
|
|||||||
using Avalonia;
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.LogicalTree;
|
using Avalonia.LogicalTree;
|
||||||
using Toolkit.UI.Controls.Avalonia;
|
using Toolkit.UI.Controls.Avalonia;
|
||||||
|
|
||||||
namespace Toolkit.UI.Avalonia;
|
namespace Toolkit.UI.Avalonia;
|
||||||
|
|
||||||
|
public class ListBoxItemExtension
|
||||||
|
{
|
||||||
|
public static readonly AttachedProperty<bool> IsItemClickEnabledProperty =
|
||||||
|
AvaloniaProperty.RegisterAttached<ListBoxItem, bool>("IsItemClickEnabled",
|
||||||
|
typeof(ListBoxItemExtension), false);
|
||||||
|
|
||||||
|
public static readonly RoutedEvent<ItemInvokedEventArgs> ItemClickEvent =
|
||||||
|
RoutedEvent.Register<ItemInvokedEventArgs>("ItemClick",
|
||||||
|
RoutingStrategies.Bubble, typeof(ListBoxItemExtension));
|
||||||
|
|
||||||
|
static ListBoxItemExtension()
|
||||||
|
{
|
||||||
|
IsItemClickEnabledProperty.Changed.AddClassHandler<ListBoxItem>(OnIsItemClickEnabledPropertyChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void OnIsItemClickEnabledPropertyChanged(ListBoxItem sender,
|
||||||
|
AvaloniaPropertyChangedEventArgs args)
|
||||||
|
{
|
||||||
|
bool TrySetupListBox()
|
||||||
|
{
|
||||||
|
if (sender.GetLogicalAncestors().OfType<ListBox>().FirstOrDefault() is ListBox listBox)
|
||||||
|
{
|
||||||
|
void OnItemInvoked(object? _, FluentAvalonia.UI.Controls.NavigationViewItemInvokedEventArgs args)
|
||||||
|
{
|
||||||
|
if (args.InvokedItemContainer == sender)
|
||||||
|
{
|
||||||
|
sender.RaiseEvent(new ItemInvokedEventArgs { RoutedEvent = ItemClickEvent });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnSelectionChanged(object? sender, SelectionChangedEventArgs args)
|
||||||
|
{
|
||||||
|
foreach (object item in args.AddedItems)
|
||||||
|
{
|
||||||
|
if (listBox.ContainerFromItem(item) == sender)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
listBox.SelectionChanged += OnSelectionChanged;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TrySetupListBox())
|
||||||
|
{
|
||||||
|
void OnAttachedToVisualTree(object? _, VisualTreeAttachmentEventArgs __)
|
||||||
|
{
|
||||||
|
sender.AttachedToVisualTree -= OnAttachedToVisualTree;
|
||||||
|
TrySetupListBox();
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.AttachedToVisualTree += OnAttachedToVisualTree;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool GetIsItemClickEnabled(ListBoxItem element) =>
|
||||||
|
element.GetValue(IsItemClickEnabledProperty);
|
||||||
|
|
||||||
|
public static void SetIsItemClickEnabled(ListBoxItem element, bool value) =>
|
||||||
|
element.SetValue(IsItemClickEnabledProperty, value);
|
||||||
|
|
||||||
|
public static void AddItemClickHandler(ListBoxItem element, EventHandler<ItemInvokedEventArgs> handler) =>
|
||||||
|
element.AddHandler(ItemClickEvent, handler);
|
||||||
|
|
||||||
|
public static void RemoveItemClickHandler(ListBoxItem element, EventHandler<ItemInvokedEventArgs> handler) =>
|
||||||
|
element.RemoveHandler(ItemClickEvent, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public class NavigationViewItemExtension
|
public class NavigationViewItemExtension
|
||||||
{
|
{
|
||||||
public static readonly AttachedProperty<bool> IsItemClickEnabledProperty =
|
public static readonly AttachedProperty<bool> IsItemClickEnabledProperty =
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Avalonia" Version="11.1.0-beta1" />
|
<PackageReference Include="Avalonia" Version="11.1.0-beta2" />
|
||||||
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.1.0-beta1" />
|
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.1.0-beta2.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Toolkit.Foundation\Toolkit.Foundation.csproj" />
|
<ProjectReference Include="..\Toolkit.Foundation\Toolkit.Foundation.csproj" />
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:fluent="using:FluentAvalonia.Styling"
|
xmlns:fluent="using:FluentAvalonia.Styling"
|
||||||
xmlns:labs="using:Avalonia.Labs.Controls">
|
xmlns:labs="using:Avalonia.Labs.Controls">
|
||||||
<fluent:FluentAvaloniaTheme />
|
|
||||||
<StyleInclude Source="ControlResources.axaml" />
|
<StyleInclude Source="ControlResources.axaml" />
|
||||||
<labs:ControlThemes />
|
<labs:ControlThemes />
|
||||||
</Styles>
|
</Styles>
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
using Avalonia.Styling;
|
using FluentAvalonia.Styling;
|
||||||
|
|
||||||
namespace Toolkit.UI.Controls.Avalonia;
|
namespace Toolkit.UI.Controls.Avalonia;
|
||||||
|
|
||||||
public class ThemeResources :
|
public class ThemeResources : FluentAvaloniaTheme
|
||||||
Styles
|
|
||||||
{
|
{
|
||||||
public ThemeResources(IServiceProvider? provider = null)
|
public ThemeResources(IServiceProvider? provider = null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Avalonia" Version="11.1.0-beta1" />
|
<PackageReference Include="Avalonia" Version="11.1.0-beta2" />
|
||||||
<PackageReference Include="Avalonia.Labs.Controls" Version="11.0.10.1" />
|
<PackageReference Include="Avalonia.Labs.Controls" Version="11.0.10.1" />
|
||||||
<PackageReference Include="FluentAvaloniaUI" Version="2.1.0-preview1" />
|
<PackageReference Include="FluentAvaloniaUI" Version="2.1.0-preview1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user