Add ContentIcon control
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Templates;
|
||||
using Avalonia.LogicalTree;
|
||||
|
||||
namespace Toolkit.Controls.Avalonia;
|
||||
|
||||
public class ContentIcon : FluentAvalonia.UI.Controls.FAIconElement
|
||||
{
|
||||
public static readonly StyledProperty<IDataTemplate> IconTemplateProperty =
|
||||
AvaloniaProperty.Register<ContentIcon, IDataTemplate>("IconTemplate");
|
||||
|
||||
public static readonly StyledProperty<object> IconProperty =
|
||||
AvaloniaProperty.Register<ContentIcon, object>("Icon");
|
||||
|
||||
public object Icon
|
||||
{
|
||||
get => GetValue(IconProperty);
|
||||
set => SetValue(IconProperty, value);
|
||||
}
|
||||
|
||||
private ContentControl? content;
|
||||
|
||||
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
{
|
||||
if (VisualChildren.Count > 0)
|
||||
{
|
||||
((ILogical)VisualChildren[0]).NotifyAttachedToLogicalTree(e);
|
||||
}
|
||||
|
||||
base.OnAttachedToLogicalTree(e);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
{
|
||||
if (VisualChildren.Count > 0)
|
||||
{
|
||||
((ILogical)VisualChildren[0]).NotifyDetachedFromLogicalTree(e);
|
||||
}
|
||||
|
||||
base.OnDetachedFromLogicalTree(e);
|
||||
}
|
||||
|
||||
|
||||
public IDataTemplate IconTemplate
|
||||
{
|
||||
get => GetValue(IconTemplateProperty);
|
||||
set => SetValue(IconTemplateProperty, value);
|
||||
}
|
||||
|
||||
protected override Size MeasureOverride(Size availableSize)
|
||||
{
|
||||
if (content == null)
|
||||
{
|
||||
CreateContent();
|
||||
}
|
||||
|
||||
return base.MeasureOverride(availableSize);
|
||||
|
||||
}
|
||||
|
||||
private void CreateContent()
|
||||
{
|
||||
content = new ContentControl();
|
||||
|
||||
content.Bind(ContentControl.ContentProperty, this.GetBindingObservable(IconProperty));
|
||||
content.Bind(ContentControl.ContentTemplateProperty, this.GetBindingObservable(IconTemplateProperty));
|
||||
|
||||
LogicalChildren.Add(content);
|
||||
VisualChildren.Add(content);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Toolkit.Controls.Avalonia;
|
||||
|
||||
public class FAIconElement : FluentAvalonia.UI.Controls.FAIconElement
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using Avalonia.Styling;
|
||||
|
||||
namespace Toolkit.Controls.Avalonia;
|
||||
|
||||
public class FAPathIcon : FluentAvalonia.UI.Controls.FAPathIcon
|
||||
{
|
||||
}
|
||||
|
||||
public class SymbolIcon : FluentAvalonia.UI.Controls.SymbolIcon
|
||||
{
|
||||
|
||||
}
|
||||
@@ -5,4 +5,4 @@ namespace Toolkit.Controls.Avalonia;
|
||||
public class NavigationViewItem : FluentAvalonia.UI.Controls.NavigationViewItem, IStyleable
|
||||
{
|
||||
Type IStyleable.StyleKey => typeof(FluentAvalonia.UI.Controls.NavigationViewItem);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<Styles xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<Styles.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries />
|
||||
</ResourceDictionary>
|
||||
</Styles.Resources>
|
||||
</Styles>
|
||||
@@ -1,5 +1,6 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Templates;
|
||||
using System.Diagnostics;
|
||||
using Toolkit.Framework.Foundation;
|
||||
|
||||
namespace Toolkit.Framework.Avalonia;
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
using Mediator;
|
||||
|
||||
namespace Toolkit.Framework.Foundation;
|
||||
|
||||
public record Create(Type Type, params object?[] Parameters) : IRequest<object?>;
|
||||
@@ -0,0 +1,17 @@
|
||||
using Mediator;
|
||||
|
||||
namespace Toolkit.Framework.Foundation;
|
||||
|
||||
public class ServiceFactoryHandler : IRequestHandler<Create, object?>
|
||||
{
|
||||
private readonly IServiceFactory factory;
|
||||
|
||||
public ServiceFactoryHandler(IServiceFactory factory)
|
||||
{
|
||||
this.factory = factory;
|
||||
}
|
||||
public async ValueTask<object?> Handle(Create request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await Task.FromResult(factory.Create(request.Type, request.Parameters));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user