awesome-inc / FontAwesome.Sharp

A library for using Font Awesome in WPF & Windows Forms applications
Apache License 2.0
385 stars 89 forks source link

making a simple string parser to insert the icon #2

Closed furesoft closed 8 years ago

furesoft commented 8 years ago

hi, pls add a string parser to add icons to textblock, rtb, etc like this:

:btc: is a cryptocurrency. :EURO: is a fiat money

mkoertgen commented 8 years ago

Ah, i see. Nice idea.

Some thoughts on this. The parser would

The generated inline for the textblock could be equivalent to this XAML

<TextBlock FontFamily="<some other font>">
  <Run Text="[&#xf15a;" FontFamily="/FontAwesome.Sharp;component/fonts/#FontAwesome"/>
  <Run Text=": is a cryptocurrency. "/>
  <Run Text="&#xf153;" FontFamily="/FontAwesome.Sharp;component/fonts/#FontAwesome"/>
  <Run Text=": is a fiat money"/>
</TextBlock>

Is that kind of what you had in mind?

mkoertgen commented 8 years ago

Usage could be like this

<fa:.....TextBlock Text=":btc: is a cryptocurrency. :EURO: is a fiat money" />

This would allow binding a text which includes icon-tags. Nice.

I would suggest to get close to the standard c# string interpolation syntax for icon-tags like this

<fa:.....TextBlock Text="{fa:btc}: is a cryptocurrency. {fa-euro}: is a fiat money" />

I'm not sure yet if subclassing a text block would be a good fit. Maybe an attached behavior would suit better.

Here is an example where we used an attached behavior to format highlighted search results from elasticsearch back into a textblock

https://github.com/mkoertgen/hello.elastic.facetedSearch.wpf/blob/e21eb12e4fd3110afa65ce4dc1281b3c07c43bea/HelloFacets/Attached.cs

mkoertgen commented 8 years ago

@furesoft Right now, i have no time for this. Feel free to contribute and do a pull request.

mkoertgen commented 8 years ago

Hi @furesoft. Had some spare time, so i added an inline parser as suggested using the attached property fa:Awesome.Inline.

Please check out v4.6.3 and let me know if this works out for you.