Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Added: markup extension #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README-WPF.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ You can also work with existing ContentControl based controls, like Button, with
TextElement.FontFamily="pack://application:,,,/FontAwesome.WPF;component/#FontAwesome"/>
```

Or use markup extension

```xaml
<Button Content="{fa:FontAwesome Flag}" TextElement.FontFamily="pack://application:,,,/FontAwesome.WPF;component/#FontAwesome"/>

<TextBlock Text="{fa:FontAwesome Flag}" FontFamily="pack://application:,,,/FontAwesome.WPF;component/#FontAwesome"/>
```

> VS2013 XAML Designer has issues when using fonts embedded in another assembly (like this scenario), which prevents it to dispaly the glyph properly.
You could either grab a copy of TTF font file and include it in you Project as a Resource, so to use it in FontFamily, or you could follow the advices proposed in this [StackOverflow thread](http://stackoverflow.com/questions/29615572/visual-studio-designer-isnt-displaying-embedded-font/29636373#29636373).

Expand Down
34 changes: 34 additions & 0 deletions src/WPF/FontAwesome.WPF/FontAwesomeExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Markup;

namespace FontAwesome.WPF
{
/// <summary>
/// Markup extension for easy converting from icon enum to string
/// </summary>
public class FontAwesomeExtension : MarkupExtension
{
/// <summary>
/// Icon.
/// </summary>
public FontAwesomeIcon Icon { get; set; }

public FontAwesomeExtension()
{
}


public FontAwesomeExtension(FontAwesomeIcon icon)
{
this.Icon = icon;
}

public override object ProvideValue(IServiceProvider serviceProvider)
{
return char.ConvertFromUtf32((int)Icon);
}
}
}