I’m developing a software in C# using Avalonia (It’s the first time I’ve used it and I still have some difficulty).
I added the FluentAvaloniaUI nuget package for the controls and LucideAvalonia for the icons.
navigationview binding works perfectly
<ui:NavigationView MenuItemsSource="{Binding Items}">
<ui:NavigationView.MenuItemTemplate>
<DataTemplate DataType="models:MainMenuItem">
<ui:NavigationViewItem Content="{Binding Title}" IconSource="{Binding Icon}"/>
</DataTemplate>
</ui:NavigationView.MenuItemTemplate>
</ui:NavigationView>
this is the MainMenuItem model (I have an observable list in the viewmodel initialized in the constructor)
i would like to change the Icon type from string to LucideIconNames (Lucide icons enumerator)
public class MainMenuItem
{
public string Title { get; init; }
public string Icon { get; init; }
public Control View { get; init; }
}
but I’m not crazy about icons, so I would like to use the LucideAvalonia icons.
however the icon control of the NavigationViewItem is FluentAvalonia.UI.Controls.IconSource and I have difficulty changing it.
This is what i tryied in the UserControl.Styles, but obviously it doesn’t work
<Style Selector="uip|NavigationViewItemPresenter /template/ ContentPresenter#Icon">
<Setter Property="Content">
<Template>
<lucideAvalonia:Lucide Icon="House" StrokeBrush="SaddleBrown" />
</Template>
</Setter>
</Style>
Can anyone help me? even just with some hints.
The Lucide
object is just a user control that wraps a DrawingImage. In this case I would avoid using this user control. Instead, import the raw ResourceDictionary from Lucide into your project which has the DrawingImage
s. DrawingImage
implements IImage, and the FluentAvalonia IconSource appears to have a built-in type converter for that, so you can use them directly.