Meditor SourceGen doesn't work for our needs right now, so let's build something on top of their library that allows us to do manual registration for now.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Templates;
|
||||
using Avalonia.LogicalTree;
|
||||
using Avalonia.Metadata;
|
||||
|
||||
namespace Toolkit.Controls.Avalonia;
|
||||
|
||||
@@ -10,13 +11,14 @@ 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 static readonly StyledProperty<object> ContentProperty =
|
||||
AvaloniaProperty.Register<ContentIcon, object>("Content");
|
||||
|
||||
public object Icon
|
||||
[Content]
|
||||
public object Content
|
||||
{
|
||||
get => GetValue(IconProperty);
|
||||
set => SetValue(IconProperty, value);
|
||||
get => GetValue(ContentProperty);
|
||||
set => SetValue(ContentProperty, value);
|
||||
}
|
||||
|
||||
private ContentControl? content;
|
||||
@@ -64,7 +66,7 @@ public class ContentIcon : FluentAvalonia.UI.Controls.FAIconElement
|
||||
{
|
||||
content = new ContentControl();
|
||||
|
||||
content.Bind(ContentControl.ContentProperty, this.GetBindingObservable(IconProperty));
|
||||
content.Bind(ContentControl.ContentProperty, this.GetBindingObservable(ContentProperty));
|
||||
content.Bind(ContentControl.ContentTemplateProperty, this.GetBindingObservable(IconTemplateProperty));
|
||||
|
||||
LogicalChildren.Add(content);
|
||||
|
||||
@@ -1,8 +1,34 @@
|
||||
using Avalonia.Styling;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Styling;
|
||||
using Avalonia.VisualTree;
|
||||
using FluentAvalonia.UI.Controls;
|
||||
|
||||
namespace Toolkit.Controls.Avalonia;
|
||||
|
||||
public class NavigationViewItem : FluentAvalonia.UI.Controls.NavigationViewItem, IStyleable
|
||||
{
|
||||
private NavigationView? navigationView;
|
||||
|
||||
public event EventHandler<NavigationViewItemInvokedEventArgs> Invoked;
|
||||
|
||||
Type IStyleable.StyleKey => typeof(FluentAvalonia.UI.Controls.NavigationViewItem);
|
||||
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs args)
|
||||
{
|
||||
navigationView = this.FindAncestorOfType<NavigationView>();
|
||||
if (navigationView is not null)
|
||||
{
|
||||
navigationView.ItemInvoked += OnItemInvoked;
|
||||
}
|
||||
|
||||
base.OnApplyTemplate(args);
|
||||
}
|
||||
|
||||
private void OnItemInvoked(object? sender, NavigationViewItemInvokedEventArgs args)
|
||||
{
|
||||
if (args.InvokedItemContainer == this)
|
||||
{
|
||||
Invoked?.Invoke(this, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user