Search code examples
c#xamlvisual-studio-2012windows-phonefontello

How to use fontello icons in cs file?


I want to add fontello icons to map dynamically in a windows phone application.I don't know how to do.I can add some shapes on map but I don't know how to add fontello icons instead of ellipse.

public void pushPin(Microsoft.Phone.Maps.Controls.Map map, GeoCoordinate position)
    {

        map.Center = position;
        map.ZoomLevel = 9;

        Ellipse myCircle = new Ellipse();
        myCircle.Fill = new SolidColorBrush(Colors.Blue);
        myCircle.Height = 15;
        myCircle.Width = 15;
        myCircle.Opacity = 20;

        var mapOverLay = new MapOverlay();
        mapOverLay.Content = myCircle;

        mapOverLay.GeoCoordinate = position;

        var mapLayer = new MapLayer();
        mapLayer.Add(mapOverLay);

        map.Layers.Add(mapLayer);

       } 

map with fontello icons


Solution

  • You need to use a TextBlock as the MapOverlay content, and set it's fontfamily to your font and text to unicode value of the symbol that you want to use.

    Assuming you are keeping your font file fontello.ttf under the root directory, the following code should do:

    public void pushPin(Microsoft.Phone.Maps.Controls.Map map, GeoCoordinate position)
    {
    
        map.Center = position;
        map.ZoomLevel = 9;
    
        TextBlock tb = new TextBlock();
        tb.FontFamily = new FontFamily("/fontello.ttf#fontello");
        tb.Text = "\uE800";
    
        var mapOverLay = new MapOverlay();
        mapOverLay.Content = tb;
    
        mapOverLay.GeoCoordinate = position;
    
        var mapLayer = new MapLayer();
        mapLayer.Add(mapOverLay);
    
        map.Layers.Add(mapLayer);  
    
    }
    

    Hope it helps.