Comments (4)
@artoriazz MahApps.Metro.IconPacks is not able to support Avalonia yet. It's planned for the future, but I have no due date for you.
from mahapps.metro.iconpacks.
Yeah, you can for example open the Icon.Browser and copy the Path-Data. This can be used for Path
or PathIcon
(avalonia v11.0 preview versions only). The Path-Data can also be added to Resources
using like this:
<!-- in any Resources node: -->
<PathGeometry x:Key="MaterialLight.PresentationPlay">
M 2,4L 10,4C 10,3.44772 10.4477,3 11,3L 12,3C 12.5523,3 13,3.44772 13,4L 21,4L 21,5L 20,5L 20,16L 14.2679,16L 15.8756,22L 14.8404,22L 13.2327,16L 9.76733,16L 8.15963,22L 7.12436,22L 8.73205,16L 3,16L 3,5L 2,5L 2,4 Z M 19,15L 19,5.00001L 4,5.00001L 4,15L 19,15 Z M 10,7L 11,7L 14,10L 11,13L 10,13L 10,7 Z M 11,8.41422L 11,11.5858L 12.5858,10L 11,8.41422 Z
</PathGeometry>
<!-- usage -->
<Path Data="{DynamicResource MaterialLight.PresentationPlay}" Width="40" Height="40" />
from mahapps.metro.iconpacks.
Support for Avalonia would be great! Is there any workaround that could be done in the meantime to use the icons in Avalonia?
from mahapps.metro.iconpacks.
Okay so last night I came up with a “temporal” (IDK when Avalonia will be supported) solution to this problem:
public class MahAppsIconControl : TemplatedControl
{
public static readonly StyledProperty<Enum> IconKindProperty =
AvaloniaProperty.Register<MahAppsIconControl, Enum>(
nameof(IconKind));
public Enum IconKind
{
get => GetValue(IconKindProperty);
set => SetValue(IconKindProperty, value);
}
public static readonly DirectProperty<MahAppsIconControl, Geometry> IconGeometryProperty =
AvaloniaProperty.RegisterDirect<MahAppsIconControl, Geometry>(
nameof(IconGeometry), o =>
{
Enum iconKind = o.GetValue(IconKindProperty);
string? path = PackIconControlDataFactory.DataIndex.Value
.Where(x => x.Key.Equals(iconKind))
.Select(x => x.Value)
.FirstOrDefault();
Geometry geometry = Geometry.Parse(path ?? string.Empty);
return geometry;
});
private Geometry iconGeometry;
public Geometry IconGeometry
{
get { return iconGeometry; }
private set { SetAndRaise(IconGeometryProperty, ref iconGeometry, value); }
}
}
And the axaml:
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:ProjectName.Controls">
<Design.PreviewWith>
<controls:MahAppsIconControl />
</Design.PreviewWith>
<Style Selector="controls|MahAppsIconControl">
<!-- Set Defaults -->
<Setter Property="Foreground" Value="White"/>
<Setter Property="Template">
<ControlTemplate>
<Image>
<Image.Source>
<DrawingImage>
<DrawingImage.Drawing>
<GeometryDrawing
Brush="{Binding Foreground, RelativeSource={RelativeSource TemplatedParent}}"
Geometry="{Binding IconGeometry, RelativeSource={RelativeSource TemplatedParent}}"/>
</DrawingImage.Drawing>
</DrawingImage>
</Image.Source>
</Image>
</ControlTemplate>
</Setter>
</Style>
</Styles>
Usage:
<controls:MahAppsIconControl Foreground="Blue" IconKind="{x:Static iconPacks:PackIconBoxIconsKind.RegularGhost}" Height="100" Width="100"/>
It works pretty good, but with some exceptions. One of them being that all the icons from the BoxIcons
library are flipped vertically for example, I don't know why. I checked the source code and the icon paths seem to be flipped vertically for some reason.
EDIT: Added null-coalescing, spelling.
from mahapps.metro.iconpacks.
Related Issues (20)
- bug: bound icons in an ItemsControl are shown incorrectly. Error appeared on 4.4.0 (it did work correctly on 4.3.0) HOT 2
- "MahApps.Metro.IconPacks.Core" Nuget-Package
- Drop .NET Framework 4.5.2 and 4.6 which will reach End of Support on April 26, 2022
- Question: how to convert an icon to System.Drawing.Icon? HOT 1
- Include the Microsoft Windows11 explorer icons
- iconPacks:PackIconSimpleIcons HOT 1
- UWP Crashes at Startup when built in Release mode when using some Icon Packs HOT 10
- Could not load file or assembly 'MahApps.Metro.IconPacks.FontAwesome, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0c0d510f9915137a' or one of its dependencies. The system cannot find the file specified. HOT 2
- VS2022 WPF Designer Crashes Most Times with Icons HOT 3
- Material Design Icons v7.0.96
- Publish icon file generators for use in PRs HOT 2
- Drop the UWP support because it's a mess with the new Sdk project files
- VS2022 can't find IconPacks resource HOT 9
- Flipped icon paths? HOT 1
- Update RemixIcon to V3.5 HOT 2
- IconPack spin not working HOT 1
- Is there any plan to update the Nuget version recently?
- IconPacks for MAUI
- Merge all dlls into one HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mahapps.metro.iconpacks.