Coder Social home page Coder Social logo

mahapps / mahapps.metro.iconpacks Goto Github PK

View Code? Open in Web Editor NEW
1.7K 62.0 211.0 79.37 MB

Awesome icon packs for WPF and UWP in one library

License: MIT License

C# 100.00% PowerShell 0.01%
icons icon-pack uwp wpf mahapps octicons material material-design material-ui fontawesome

mahapps.metro.iconpacks's Introduction


MahApps.Metro.IconPacks

MahApps.Metro
IconPacks

Awesome icon packs for WPF and UWP in one library

Supporting .NET Framework >= 4.6.2, >= .NET Core 3.1, >= .NET 5 (on Windows) and UWP (uap10.0.18362)

Discord X (formerly Twitter) Follow Mastodon Follow
AppVeyor Build (with branch) AppVeyor Build (with branch) GitHub Actions Workflow Status

This IconPacks library contains controls, markup extensions and converters to use these awesome icons in a simple way.

Icon collection Version โˆ‘ NuGet
Complete IconPacks collection with all Icons in one package
Bootstrap Icons 1.11.3 2050
Boxicons 2.1.4 1634
Codicons 0.0.35 438
Coolicons 4.1 442
Entypo+ 411
Eva Icons 1.1.3 490
Feather Icons 4.29.1 287
File Icons 2.1.47 920
Fontaudio 1.1.0 155
Font Awesome Free 6.5.2 2045
Fontisto 3.0.4 616
Fork Awesome 1.2.0 794
Ionicons 4.6.4.1 696
Jam Icons 3.1.0 940
Material Design Icons 7.4.47 7447
Material Design Icons Light 0.2.63 257
Material design icons (Google) 3.0.1 932
Memory Icons 1.5.0 651
Microns 1.0.10 108
Modern UI Icons 1260
GitHub Octicons 9.6.0 204
PICOL Icons 1.1.0 549
Pixelarticons Free 1.7.0 480
Radix Icons 1.0.3 312
Remix Icon 4.2.0 2850
RPG Awesome 0.2.0 495
Simple Icons 7.14.0 2379
Typicons 2.1.2 336
Unicons 2.1.11 1184
Vaadin Icons 4.3.2 636
Weather Icons 2.0.10 219
Zondicons 297

Note

It's not necessary, but you can use these Icons together with MahApps.Metro which makes your WPF application nicer.

Let's get started

Want to say thanks?

This framework is free and can be used for free, open source and commercial applications.

It's tested and contributed by many people... So mainly hit the โญ button, that's all... thx :squirrel: (๐Ÿ’ต, ๐Ÿ’ถ, ๐Ÿบ or some other gifts are also being accepted...).

Please give also a star to all available icon repositories.

Become a sponsor and show your support to this open source project.

IconPacks Browser

The Browser for all available Icon packages can be found here.

iconbrowserfinal

mahapps.metro.iconpacks's People

Contributors

blackgad avatar eiadxp avatar gitter-badger avatar igorushi avatar jizc avatar mareksagan avatar mongeon avatar punker76 avatar schdck avatar timunie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mahapps.metro.iconpacks's Issues

Tiny simple editor

Add a tiny simple editor to change size, background and foreground and copy the result as Xaml into the clipboard...

Add possibility to have PackIconModernKind.None

I want to use PackIconModern with Triggers and have a empty image on default. Because the enumeration memeber None is missing, I do not have a empty image but the default value _3d3ds.
Can you please implement this to have an empty PackIconXXX?

For now I have to use the workarout with Visibility.Hidden.

Iconpacks precompiled browser (.exe) triggers antivirus

Symantec anti virus has quarantined (deleted) the icon packs browser executable from my computer.

Threat: Heur.AdvML.B

File: IconPacks.Browser.v2.2.0.zip>>MahApps.Metro.IconPacks.Browser.exe

Action taken: Cleaned by Deletion

Error: 'Flip' property was already registered by 'MahApps_Metro_IconPacks_PackIconControl`1_13_147733582'

Hi,
I get the following error every time i use any icons from MahApps.Metro.IconPacks in my WPF project in VS2017:

Error: 'Flip' property was already registered by 'MahApps_Metro_IconPacks_PackIconControl`1_13_147733582'

Packages i have installed in the project include:
MahApps.Metro
MahApps.Metro.IconPacks
ControlzEx (Installed as a dependency automatically, i don't manually install it)

All the installations were done using NuGet Package manager in VS2017.

Pls note that, due to the above error, the XAML visualizer doesn't show the Icons at design time, but at run time the icons appear correctly. The way i am using the Icons in my buttons is the following:

I have tried several things but am unable to find a solution; Google search didn't bring any results either. Hoping to get a resolution on this. Thank you.

Font Awesome 5.0 naming

The new Font Awesome 5.0 introduce new sub groups Regular, Solid and Brands, so I want to know which is the best name for the enumeration.

far_FontAwesomeName
fas_FontAwesomeName
fab_FontAwesomeName
FontAwesomeNameRegular
FontAwesomeNameSolid
FontAwesomeNameBrands
RegularFontAwesomeName
SolidFontAwesomeName
BrandsFontAwesomeName

Missing Material Icons

These icons are missing:

  • BatteryCharging10
  • BatteryCharging50
  • BatteryCharging70
  • BatteryChargingOutline

Spin property still doesn't work during runtime

My ViewModel contains:
public ObservableCollection<LogEntry> LogEntries { get; } = new ObservableCollection<LogEntry>();

with a UserControl for log entries:
UserControl.xaml.txt

which is added to a MetroWindow via a TransitioningContentControl.

Everything works - Text binding, icon binding, color binding - as far as the icons themselves are concerned, but they don't spin. Even if I change the binding to a static value of in the .xaml like Spin="True".

LogEntry class for reference, just in case, but it shouldn't make any difference:
LogEntry.cs.txt

Constructor Error when using MarkupExtension

I get the following error:

The type "PackIconFontAwesomeExtension" does not include a constructor that has the specified number of arguments.

When I try to use the following demo material (using the Markup Extension in WPF):
<Button Content="{iconPacks:PackIconFontAwesome StarOutline}" />

My Visual Studio Designer shows an Invalid Markup error message also.

My workaround right now is to use the general ("generic") markup extension:
Content="{iconPacks:PackIcon {x:Static iconPacks:PackIconModernKind.Settings}}" />

Can you check, if you can reproduce this error?

using icons in NavigationView of UWP

I was trying to use some icons in the NavigationView of my uwp app but as it turns out NavigationViewItem.Icon only accepts following types.

  1. SymbolIcon
  2. BitmapIcon
  3. FontIcon

and since IconPacks is not any of those how can they be used in this scenario?

Designer and execution error due to "Flip" property

I'm getting the following error while trying to add an icon, they are working in 2 computers but not in the others.

Flip property was already registered by 'MahApps_Metro_IconPacks_PackIcon1_0_195866302' .`

Cannot resolve ControlzEx when Mahapps Metro used

Hi All,

I have a weird one where i have an app developed using WPF and Metro and i have just added the icons pack but i cannot use any of the icons because i get the issue;

'Cannot resolve dependency to assembly 'ControlzEx, Version=3.0.2.4, Culture=neutral, PublicKeyToken=null' because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event. Line 92 Position 64.'

Any ideas?

IconPack in UWP Causes Designer to Fail

Utilizing the IconPack Nuget package, VS2015 designer crashes and fails to restart. It is worth noting that the application builds fine - designer is the only item that is having issues. The error output I am given is as follows:

System.Runtime.Remoting.RemotingException
[13836] Designer process terminated unexpectedly!

The actual issue does not arise until I actually use an icon:

<IconPack:PackIconMaterial Kind="Settings" />

Simply placing the using statement raises no issues.

Icon for IconPacks library

It would be cool to have an awesome icon (logo) for this library itself. This icon (logo) will then be used then here on the GitHub repository and for the NuGet packages.

If you have an idea about an icon or if you have time and you are a designer then go for it ๐Ÿ‘ ๐Ÿ˜ƒ

Your name will be honored and linked to your site or whatever here on this repo and can be find at the README. It's also possible to pay out your work.

Thx!

Designer error in a 'custom' style 'Setter' for an icon

The title of the issue is not clear, sorry for this.
I'm using the last version of the IconPacks (1.6.0) and I have tried to change directly the 'ButtonsExample.xaml' file in the 'MahApps.Metro.Demo.Shared' to replicate my problem.

I have the necessity to change an Icon when change a property. To do this I have set an 'inline' style for the icon with a DataTrigger to change the 'Kind' property to the desired icon.
This is my code (I have added a checkbox with an icon as content, and I want to change the icon when change the IsChecked property of the checkbox):

  <CheckBox Margin="{StaticResource ControlMargin}" IsChecked="True">
    <iconPacks:PackIconModern>
      <iconPacks:PackIconModern.Style>
        <Style TargetType="{x:Type iconPacks:PackIconModern}">
          <Setter Property="Kind" Value="Check" />
          <Style.Triggers>
            <DataTrigger Binding="{Binding IsChecked, RelativeSource={RelativeSource AncestorType=CheckBox}}" Value="False">
              <Setter Property="Kind" Value="Close" />
            </DataTrigger>
          </Style.Triggers>
        </Style>
      </iconPacks:PackIconModern.Style>
    </iconPacks:PackIconModern>
  </CheckBox>

With this 'code' the Designer mark the Property="Kind" as wrong with the message:
The property "Kind" is not a DependencyProperty. To be used in markup, non-attached properties must be exposed on the target type with an accessible instance property "Kind".
(In my project the error is: the member "Foreground" is not recognized or is not accessible (this because I have tried to change the foreground color in the datatrigger)

What I have seen is that if I change the TargetType from "{x:Type iconPacks:PackIconModern}" to "iconPacks:PackIconModern" (without {x:Type), the designer works correctly.

I don't know if this is a real bug, and for the moment I have the workaround, but with the older version, this effect was not present.

Thanks

Create a short Wiki

Create a short Wiki from the already existing README with some simple examples.

Icon Pull Frequency

First off, thank you for putting this together and all of the hard work you have put into your projects!

How often do you pull icons from the sources? I contributed to Material Design with the intention of getting access to it through this icon pack.

Binding to icon type and kind, from string

I have an application that currently uses the loose xaml icon file from MahApps.Metro.Resources. The application retrieves a large collection of objects from a database, including a string representing the resource key of the icon (for example, appbar_lock). I then use a converter (using TryFindResource) to convert the string to a matching resource key.

This setup works fairly well for me, and I'm able to store the object's icon with all of the other metadata in the database. However, I'd like to move to the newer IconPacks in order to take advantage of the continuing support and additional icons.

Is there a way to accomplish this setup within IconPacks?

"Margin" and "Foreground" properties for Octicons & FontAwesome

After a update from version 1.9* to 2.2.0 :
"Margin" and "Foreground" properties are not found for "Octicons" & "FontAwesome"
But they still still exist for "PackIconMaterial"
Sample :

 <MenuItem.Icon>
<iconPacks:Octicons Kind="Sync" Margin="5 0 0 0" Foreground="{DynamicResource xxxx}"/>
 </MenuItem.Icon> 

Add signed version of the assembly

Hi,

I wanted to use this library in my application but can't because my application is requires strong named assemblies. All other MahApps packages are signed, can you please add this one as well?

Thanks

Use Iconpack as Image

Hi everyone

I want to use some Icons if this Pack as Images, so everthink looks the same.
But i don't know how to access the Images ....

`xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"

this works : <Button Content="{iconPacks:PackIconMaterial Settings}"

here i wan't to use the Image ... This doesn't work :
<myWPF:ImageButton Image="{iconPacks:PackIconMaterial Settings}" `

So how can i get or convert the iconPacks to an Image Source ?

Update Control Name to Match MarkupExtension

Currently, if I use an Icon as its own control, I have to use the following syntax:

<IconPacks:PackIconFontAwesome Kind="BookmarkRegular" />

If I use the icon as a MarkupExtension, the syntax is slightly different (specifically, PackIconFontAwesome becomes a simple FontAwesome, which I think is perfect):

<Button Content="{iconPacks:FontAwesome Kind=BookmarkRegular}" />

Can the control syntax be updated to match the MarkupExtension syntax for consistency? Example:

<IconPacks:FontAwesome Kind="BookmarkRegular" />

After Install Package not running

Hi everyone

I'm trying to use your package.

I launch the Install-Package MahApps.Metro.IconPacks on my wpf projet in vs 2017 community.

After that, I'm starting to use th icon pack.

  1. I add xmlns : xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"

  2. I try this <iconPacks:PackIconMaterial Kind="EmoticonCool" VerticalAlignment="Center" HorizontalAlignment="Center" />

But PackIconMaterial is not recognized.

Whats is happening ?

PackIconBase conflict with ControlzEx from MahApps.Metro

Hello,

I use base class for icon packs, PackIconBase, in base styles and also as content of some custom controls, so that I can use all iconsets. It is the only non-generic common ancestor before Control.

Since MahApps.Metro 1.6, it depends from ControlzEx nuget package. So when I have both MahApps.Metro and MahApps.IconPacks installed, all my usages of PackIconBase produce the following error:
Error CS0433 The type 'PackIconBase' exists in both 'ControlzEx, Version=3.0.2.4, Culture=neutral, PublicKeyToken=null' and 'MahApps.Metro.IconPacks, Version=2.1.0.15, Culture=neutral, PublicKeyToken=null'

I wonder if it's better for MahApps.Metro.IconPacks to use ControlzEx package as well?

Icon binds only to first datagrid row

If I add an icon to a button in a datagrid in WPF everything works just fine.
But when I try to use it inside a DataTrigger, only the first row of my datagrid shows an image.

<Button>
    <Button.Style>
        <Style TargetType="Button">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Order_Status.In_Prima}" Value="true">
                    <Setter Property="Content" Value="{iconPacks:PackIconFontAwesome StarOutline}" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Order_Status.In_Prima}" Value="false">
                    <Setter Property="Content" Value="{iconPacks:PackIconFontAwesome StarOutline}" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Button.Style>
<Button>

Using FontAwesome icons inside Image leads to inversed visuals

Hi there,

when using the current FontAwesome Iconpack (v1.9.1 or .0) the icons are displayed like this when embedding as Image inside XAML code using an custom converter (bool to icon):

fontawesome

Here is the code of the converter:

https://gist.github.com/gimmebytes/0d217c2261ce7ea60f33a2ae2db93958

And here the binding inside the XAML code:

<Image Height="24" Width="24" Source="{Binding SomeObject.BoolField, Converter={StaticResource IconConverter}}" />

When using the Modern Icon Pack everything is working fine. Havn't tested other packs yet.

Any help is appreciated, thanks in advance!

Icon spin property not working at runtime

Hey, I can't seem to get a simple example of an icon with spin set true working.

The following code causes the icon to spin in the design window, but not in a running app. Bizarre. Any other information I can provide or ideas of what I can check?

<Window x:Class="IconPacksTest.App"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
        Title="IconPacks" Height="300" Width="300">

   <Grid>
     <iconPacks:PackIconMaterial Kind="EmoticonCool" Spin="True" VerticalAlignment="Center" HorizontalAlignment="Center" />
   </Grid>

</Window>

MarkupExtension Namespace vs Name change

There is a problem with the current MarkupExtension naming and namespace. Visual Studio has problems with the properties of the MarkupExtension classes. The extensions doesn't have DependencyProperty implementations for the properties, but VS see this properties e.g. in a style and mark this usage with a warning.

The property "Kind" is not a DependencyProperty. To be used in markup, non-attached properties must be exposed on the target type with an accessible instance property "Kind".

Here are the reported issues

  • Designer error in a 'custom' style 'Setter' for an icon #29
  • Designer and execution error due to "Flip" property #30

There are now 2 solutions to solve this issue (both are breaking changes)

  1. ๐Ÿ‘ Rename the extension PackIconXYZ -> PackIconXYZExt
<Button Content="{iconPacks:PackIconMaterialExt AccessPoint}" />
  1. ๐Ÿ‘Ž Put the extension in a separated namespace
   xmlns:ip="http://metro.mahapps.com/winfx/xaml/iconpacks"
   xmlns:ipExt="http://metro.mahapps.com/winfx/xaml/iconpacks/mextensions"
<Grid>

    <StackPanel HorizontalAlignment="Center"
                VerticalAlignment="Center"
                Orientation="Vertical">
        <CheckBox IsChecked="True">
            <ip:PackIconModern>
                <ip:PackIconModern.Style>
                    <Style TargetType="{x:Type ip:PackIconModern}">
                        <Setter Property="Kind"
                                Value="Check" />
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding IsChecked, RelativeSource={RelativeSource AncestorType=CheckBox}}"
                                         Value="False">
                                <Setter Property="Kind"
                                        Value="Close" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ip:PackIconModern.Style>
            </ip:PackIconModern>
        </CheckBox>

        <Button Content="{ipExt:PackIconMaterial AccessPoint}" Margin="8" />

    </StackPanel>

</Grid>

I prefer first solution ;-)

Strong-Naming again...

The author of the (in)famous "Still strong naming your assemblies?" blog article has now done an about-face and now advocates strong-naming your assemblies again in an update to that same blog post:

Though the information and concerns in this blog post are still very true, Iโ€™ve actually had a change of heart and Iโ€™m now advocating to Start Strong-Naming your Assemblies!!

Start Strong-Naming your Assemblies!

Microsoft's corefx team also now strong-names and while they say not every assembly needs it, it's still useful: https://github.com/dotnet/corefx/blob/master/Documentation/project-docs/strong-name-signing.md

[WPF] PackIconMaterial on property Glyph

Hi,

I'm trying to use a icon from PackIconMaterial inside a property Glyph from element AppButtonBar (DevExpress) and i'm getting below error:

MahApps.Metro.IconPacks.PackIconMaterial' is not a valid value to 'Glyph' property.

My Code:

<dxwui:AppBarButton Label="Refresh" HorizontalAlignment="Center" IsEllipseEnabled="False" Glyph="{iconPacks:PackIcon {x:Static iconPacks:PackIconMaterialKind.Loop}, Width=32, Height=32}" />

There's some way to use the icons inside a Glyph?

Thanks in advance.

Enable search in multiple packs.

When I use the browser to find an icon I usually search in multiple icon packs. On each tab I need to enter a search string again. It would be nice to preserve a search term among tabs or maybe have an aggregated "all packs" tab.

How to Ingest Outside Icon Libraries

As the FA5 release date rapidly approaches (30 June, last I looked), I am going to be interested in incorporating my pro license into some of my apps. However, I know that we cannot just give away FA5 Pro Icons.

The only solution I see is for me to generate my own version of MA.M.IP, but I am unsure as to how to incorporate the FA5 Pro icons (or any icons, for that matter) into it. Can a quick-guide be generated? Or, as a separate concept, could a private repo be created that has FA5 icons incorporated, and we just control access to it? (Not sure how we can ensure access is limited to only those who have purchased the Pro pack...)

I'm also open to suggestions on any other ideas.

A suggestion on a new API design

First of all I must say I can't thank you enough for all the time and effort that your MahApps projects had saved me in my projects.
I've got a suggestion on API design of this project. The main idea came to my mind by looking at how we use Brush, Brushes classes with Foreground property on a control. Through years I've learned that using generic classes along with xaml is not good idea... It will make headaches for the developer down the road... Like having you defined different styles with exactly same xaml code for different TKind in PackIconBase... The following classes are just for demonstration of the idea so it will be easier to understand.

Design

The first class stores the icon data (It's like Brush class or even Color class, read on and you'll find out why). It can even contain other properties like the preferred Brush to draw it with, which can be ignored when it is null (In IconPresenter control template) and the Foreground of IconPresenter would be used instead.

[ContentProperty("PathData")]
public class IconData : Freezable
{
    public static IconData Empty;

    static IconData()
    {
        Empty = new IconData();
    }

    public IconData()
    {
    }

    public IconData(string pathData)
    {
        PathData = pathData;
    }

    private static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
        nameof(PathData),
        typeof(string),
        typeof(IconData),
        new PropertyMetadata(null));

    [Bindable(true), Category("Appearance")]
    public string PathData
    {
        get => (string) GetValue(PathDataProperty);
        set => SetValue(PathDataProperty, value);
    }
        
    protected override Freezable CreateInstanceCore()
    {
        return new IconData();
    }
}

The next class is an example of our libraries of icons (like Brushes class but for Modern icons).

public static class ModernIcons
{
    private static readonly object CupcakeKey = new object();
    private static readonly object BeerKey = new object();

    private static readonly IDictionary<object, IconData> Icons = new Dictionary<object, IconData>
    {
        {CupcakeKey, new IconData("M50.67,22.17A3.16,3.16 0 0,1 53.83,25.33C53.83,25.91 53.68,26.45 53.41,26.92H53.83C55.58,26.92 57,28.33 57,30.08A3.17,3.17 0 0,1 53.83,33.25H55.42C57.17,33.25 58.58,34.67 58.58,36.42A3.16,3.16 0 0,1 55.42,39.58H23.75C22,39.58 20.58,38.17 20.58,36.42A3.17,3.17 0 0,1 23.75,33.25H25.33C23.58,33.25 22.17,31.83 22.17,30.08A3.16,3.16 0 0,1 25.33,26.92H25.76C25.5,26.45 25.33,25.91 25.33,25.33C25.33,23.58 26.75,22.17 28.5,22.17C30.08,22.17 33.25,19 39.58,17.42C45.92,22.17 49.08,22.17 50.67,22.17M23.75,41.17H55.42L50.67,57H28.5L23.75,41.17Z")},
        {BeerKey, new IconData("M24,20H49L49.08,26.92C53.46,26.92 57,30.46 57,34.83V42.75A7.92,7.92 0 0,1 49.08,50.67L49,59H24V20M49,46C50.75,46 53,43.75 53,42V36C53,34.25 50.75,31 49,31V46M27,23V25H46V23H27M46,56V54H27V56H46M30.5,28C29.63,28 29,29.13 29,30V49C29,49.87 29.63,51 30.5,51C31.37,51 32,49.87 32,49V30C32,29.13 31.37,28 30.5,28M36.5,28C35.63,28 35,29.13 35,30V49C35,49.87 35.63,51 36.5,51C37.37,51 38,49.96 38,49.08V30C38,29.13 37.37,28 36.5,28M42.5,28C41.63,28 41,29.13 41,30V49C41,49.87 41.63,51 42.5,51C43.37,51 44,49.87 44,49V30C44,29.13 43.37,28 42.5,28M23.75,17.23C25,17 31.67,13.67 33.25,15.25C34.83,16.83 36.42,16.83 38,16.83C39.58,16.83 41.17,15.25 44.33,15.25C45.92,15.25 49.08,16.04 49.08,17.63C49,21 47.9,18.81 47.9,18.81C47.9,18.81 47.1,17.23 43.94,17.23C40.77,17.23 39.58,18.81 38,18.81C36.42,18.81 33.65,17.23 30.5,17.23C27.31,17.23 26.88,18.83 24.94,18.42C23,18 21,20 21.77,22C23,24 22.17,25.28 22.17,27.5C22.17,27.92 21.75,27.88 21.38,25.94C21,24 19,23.17 19,21.58C19,20 19.17,19.83 20.58,18.42C22,17 22.5,17.46 23.75,17.23Z") }
    };

    public static IconData Cupcake => Icons[CupcakeKey];
    public static IconData Beer => Icons[BeerKey];
}

And the last one is the control which hosts the icon.

public class IconPresenter : Control
{
    private static readonly DependencyProperty DataProperty = DependencyProperty.Register(
        nameof(Data),
        typeof(IconData),
        typeof(Icon),
        new PropertyMetadata(null));

    [Bindable(true), Category("Appearance")]
    public IconData Data
    {
        get => (IconData) GetValue(DataProperty);
        set => SetValue(DataProperty, value);
    }
}

Usage

<icons:IconPresenter Data="{x:Static icons:ModernIcons.Cupcake}" />

In my initial search I couldn't find a way to implement some kind of converter in designer to use strings instead of '{x:Static icons:ModernIcons.Cupcake}' just like we use 'Red' in a foreground property. But even though I could find one, I would definitely not find a way to have intellisense for that.

The developer can even have their own icons defined and use it in the same manner by StaticResource.

<controls:IconData x:Key="CustomIcon">M21,16V14L13,9V3.5A1.5,1.5 0 0,0 11.5,2A1.5,1.5 0 0,0 10,3.5V9L2,14V16L10,13.5V19L8,20.5V22L11.5,21L15,22V20.5L13,19V13.5L21,16Z</controls:IconData>

And then

<icons:IconPresenter Data="{StaticResource CustomIcon}" />

Implementation

We can define an XSD file and a couple of corresponding XML files for each icon pack. Then have a T4 text template to generate classes. The resulting solution structure will be much cleaner and easier to maintain.

NuGet

We would have MahApps.Metro.IconPacks.Core which contains the IconData and IconPresenter classes. And a separate package for each icon pack like MahApps.Metro.IconPacks.Modern which contain classes like ModernIcons. And another package MahApps.Metro.IconPacks which have dependency on all of the mentioned packages.

Browser

For browser application compatibility we can use attributes on static properties of the icon pack classes (For name, description, tags etc.)

Advantages

  1. Cleaner and simpler resulting solution structure which is easier to maintain
  2. It is more resource dictionary friendly in expandability aspect.
  3. We have just one IconPresenter class across application to have its default style set.
  4. Developers can easily define preferred brushes for icons (They are not a simple shape).
  5. Developers can use their custom icons along with our predefined icons in the same manner.
  6. If developers wants to organize their used icons in an application, They can have their own icons repository class defined. And this way they can easily switch between icons for an specific purpose.
public static class ApplicationIcons
{
    private static readonly object AppIconKey = new object();
    private static readonly object NewKey = new object();

    private static readonly IDictionary<object, IconData> Icons = new Dictionary<object, IconData>
    {
        {AppIconKey, ModernIcons.Cupcake},
        {NewKey, MaterialIcons.PlusCircleOutline}
    };

    public static IconData AppIcon => Icons[AppIconKey];
    public static IconData New => Icons[NewKey];
}

Further discussion

We can even forget about the ModernIcons and similar classes and add resource dictionaries for different icon packs and add another property named BasedOn on IconData to help the developer have an alternative solution for the ApplicationIcons class discussed above (If you prefer xaml based solutions for UI problems). But I like it more in C# manner, you know, it's a library and other people shouldn't be able to modify it easily. But this doesn't mean having BasedOn property is wrong. And of course we should handle possible loops in BasedOn parents. Or maybe, we can have another class named Icon which is responsible for storing things like Fill brush along with IconData (I like this idea more).

Summary

So suggested classes and their responsibilities are as following:

  1. IconData: Storing path data of the icon
  2. MaterialIcons: Storing IconData of the known icons in each icon pack
  3. IconPresenter: A control which shows the icon
  4. Icon**: Storing other info about icon like Fill brush along with IconData. An IconData must be easily convertable to an Icon. If defined IconPresenter would use this instead of IconData. So it's kinda like Brush class and IconData is kinda like Color class.

** Additionally suggested, but it would be nice to have something like this.

And at the end I must say fixing FlowDirection in the default style (as it is now) for hosting controls is a bad idea. Sometimes we want the icon to adapt the hosting window's FlowDirection... For example an arrow for the GO button. By overriding its FlowDirection in the default style it doesn't inherit its value from its parent container anymore so it has to be maintained manually and that is definitely a problem. By using suggested IconData (Or Icon) class we can overcome this problem too, but again, I strongly advise against it to have it hard-coded inside the library (One can use the alternative suggested approach in ApplicationIcons class for their specific requirement)

I'm open to any kind of discussion/suggestion about this idea, and in ways which it is not practical. And of course I'm willing to help in implementing it because I don't think it takes more than couple of weekends.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.