mirror of
https://gitcode.com/gh_mirrors/se/Semi.Avalonia
synced 2026-05-02 22:11:28 +08:00
fix: resolve icon AOT issue.
This commit is contained in:
@@ -1,9 +1,7 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Markup.Xaml;
|
|
||||||
using Avalonia.Media;
|
using Avalonia.Media;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
|
||||||
@@ -11,8 +9,7 @@ namespace Semi.Avalonia.Demo.ViewModels;
|
|||||||
|
|
||||||
public partial class IconDemoViewModel : ObservableObject
|
public partial class IconDemoViewModel : ObservableObject
|
||||||
{
|
{
|
||||||
private readonly IResourceDictionary? _resources =
|
private readonly IResourceDictionary? _resources = new Icons();
|
||||||
AvaloniaXamlLoader.Load(new Uri("avares://Semi.Avalonia/Icons/Icon.axaml")) as ResourceDictionary;
|
|
||||||
|
|
||||||
private readonly Dictionary<string, IconItem> _filledIcons = new();
|
private readonly Dictionary<string, IconItem> _filledIcons = new();
|
||||||
private readonly Dictionary<string, IconItem> _strokedIcons = new();
|
private readonly Dictionary<string, IconItem> _strokedIcons = new();
|
||||||
@@ -26,22 +23,27 @@ public partial class IconDemoViewModel : ObservableObject
|
|||||||
{
|
{
|
||||||
if (_resources is null) return;
|
if (_resources is null) return;
|
||||||
|
|
||||||
foreach (var key in _resources.Keys)
|
foreach (var provider in _resources.MergedDictionaries)
|
||||||
{
|
{
|
||||||
if (_resources[key] is not Geometry geometry) continue;
|
var dic = provider as ResourceDictionary;
|
||||||
var icon = new IconItem { ResourceKey = key.ToString(), Geometry = geometry };
|
if (dic?.Keys is null) continue;
|
||||||
|
foreach (var key in dic.Keys)
|
||||||
if (key.ToString().EndsWith("Stroked"))
|
|
||||||
{
|
{
|
||||||
_strokedIcons[key.ToString()] = icon;
|
if (dic[key] is not Geometry geometry) continue;
|
||||||
}
|
var icon = new IconItem { ResourceKey = key.ToString(), Geometry = geometry };
|
||||||
else
|
|
||||||
{
|
|
||||||
_filledIcons[key.ToString()] = icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
OnSearchTextChanged(string.Empty);
|
if (key.ToString().EndsWith("Stroked"))
|
||||||
|
{
|
||||||
|
_strokedIcons[key.ToString()] = icon;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_filledIcons[key.ToString()] = icon;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OnSearchTextChanged(string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
partial void OnSearchTextChanged(string? value)
|
partial void OnSearchTextChanged(string? value)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
<ResourceDictionary x:Class="Semi.Avalonia.Icons" xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||||
<ResourceDictionary.MergedDictionaries>
|
<ResourceDictionary.MergedDictionaries>
|
||||||
<ResourceInclude Source="avares://Semi.Avalonia/Icons/Icon.axaml" />
|
<ResourceInclude Source="avares://Semi.Avalonia/Icons/Icon.axaml" />
|
||||||
<ResourceInclude Source="avares://Semi.Avalonia/Icons/IconPatch.axaml" />
|
<ResourceInclude Source="avares://Semi.Avalonia/Icons/IconPatch.axaml" />
|
||||||
|
|||||||
5
src/Semi.Avalonia/Icons/_index.axaml.cs
Normal file
5
src/Semi.Avalonia/Icons/_index.axaml.cs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
using Avalonia.Controls;
|
||||||
|
|
||||||
|
namespace Semi.Avalonia;
|
||||||
|
|
||||||
|
public class Icons : ResourceDictionary;
|
||||||
Reference in New Issue
Block a user