Saturday, September 1, 2012

Enumerating local fonts in silverlight 4

Enumerating local fonts in silverlight 4

Hi How to enumerate local fonts using silverlight 4? I have tried using the javascript API given in http://forums.silverlight.net/forums/t/103128.aspx but it doesn't seem to work. Thanks NaSh

Answers & Comments...

Answer: 1

Hi avinashbabu,

You can try the following Silvelright 4 code.
It was done pretty rapidly though it should give you
the list of local fonts in a listbox... Please feel free
to modify as you wish...

xaml:

<Grid x:Name="LayoutRoot" Background="White">
      <ListBox x:Name="myFontList" Height="400" HorizontalContentAlignment="Stretch"/>
 </Grid>
--------------------------------------------------------------------------------

cs:
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace FontViewer
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            var typefaces = System.Windows.Media.Fonts.SystemTypefaces;

            foreach (System.Windows.Media.Typeface face in typefaces)
            {
                System.Windows.Media.GlyphTypeface g;
                ListBoxItem listBoxItem = new ListBoxItem();               

                face.TryGetGlyphTypeface(out g);
                FontSource fs = new FontSource(g);
                var fontname = g.FontFileName;
                listBoxItem.Content = fontname.ToString();
                myFontList.Items.Add(listBoxItem);

             }
           
        }
    }
}

If this answers your question, please Mark as an answer. Thank you.



Answer: 2 Hi MawashiKid Sorry, I maynot be clear in my post. I wanted to display the font names in a list box not the fontfile names. Is there a method to do that other than the javascript api given in the previous link. Thanks NaSh

Answer: 3

Hi Mawashikid!!!

i hv tried yr example.All fonts are not working only some of them are working...........





No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog