diff --git a/Controls/Avalonia/IconElement/ContentIcon.cs b/Controls/Avalonia/IconElement/ContentIcon.cs new file mode 100644 index 0000000..3c985a6 --- /dev/null +++ b/Controls/Avalonia/IconElement/ContentIcon.cs @@ -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 IconTemplateProperty = + AvaloniaProperty.Register("IconTemplate"); + + public static readonly StyledProperty IconProperty = + AvaloniaProperty.Register("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); + } + + /// + 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); + } +} \ No newline at end of file diff --git a/Controls/Avalonia/IconElement/FAIconElement.cs b/Controls/Avalonia/IconElement/FAIconElement.cs new file mode 100644 index 0000000..5347c44 --- /dev/null +++ b/Controls/Avalonia/IconElement/FAIconElement.cs @@ -0,0 +1,6 @@ +namespace Toolkit.Controls.Avalonia; + +public class FAIconElement : FluentAvalonia.UI.Controls.FAIconElement +{ + +} diff --git a/Controls/Avalonia/IconElement/FAPathIcon.cs b/Controls/Avalonia/IconElement/FAPathIcon.cs new file mode 100644 index 0000000..ae36a98 --- /dev/null +++ b/Controls/Avalonia/IconElement/FAPathIcon.cs @@ -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 +{ + +} diff --git a/Controls/Avalonia/NavigationView/NavigationViewItem.cs b/Controls/Avalonia/NavigationView/NavigationViewItem.cs index 0da829c..ac146ec 100644 --- a/Controls/Avalonia/NavigationView/NavigationViewItem.cs +++ b/Controls/Avalonia/NavigationView/NavigationViewItem.cs @@ -5,4 +5,4 @@ namespace Toolkit.Controls.Avalonia; public class NavigationViewItem : FluentAvalonia.UI.Controls.NavigationViewItem, IStyleable { Type IStyleable.StyleKey => typeof(FluentAvalonia.UI.Controls.NavigationViewItem); -} \ No newline at end of file +} diff --git a/Controls/Avalonia/Themes/ControlResources.axaml b/Controls/Avalonia/Themes/ControlResources.axaml new file mode 100644 index 0000000..f7b96f4 --- /dev/null +++ b/Controls/Avalonia/Themes/ControlResources.axaml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Framework/Avalonia/Templates/TemplateSelector.cs b/Framework/Avalonia/Templates/TemplateSelector.cs index 6f6bd9d..4b9c99c 100644 --- a/Framework/Avalonia/Templates/TemplateSelector.cs +++ b/Framework/Avalonia/Templates/TemplateSelector.cs @@ -1,5 +1,6 @@ using Avalonia.Controls; using Avalonia.Controls.Templates; +using System.Diagnostics; using Toolkit.Framework.Foundation; namespace Toolkit.Framework.Avalonia; diff --git a/Framework/Foundation/Services/Create.cs b/Framework/Foundation/Services/Create.cs new file mode 100644 index 0000000..76023c9 --- /dev/null +++ b/Framework/Foundation/Services/Create.cs @@ -0,0 +1,5 @@ +using Mediator; + +namespace Toolkit.Framework.Foundation; + +public record Create(Type Type, params object?[] Parameters) : IRequest; diff --git a/Framework/Foundation/Services/ServiceFactoryHandler.cs b/Framework/Foundation/Services/ServiceFactoryHandler.cs new file mode 100644 index 0000000..e89ff98 --- /dev/null +++ b/Framework/Foundation/Services/ServiceFactoryHandler.cs @@ -0,0 +1,17 @@ +using Mediator; + +namespace Toolkit.Framework.Foundation; + +public class ServiceFactoryHandler : IRequestHandler +{ + private readonly IServiceFactory factory; + + public ServiceFactoryHandler(IServiceFactory factory) + { + this.factory = factory; + } + public async ValueTask Handle(Create request, CancellationToken cancellationToken) + { + return await Task.FromResult(factory.Create(request.Type, request.Parameters)); + } +}