Typography in SilverLight 5 Via WCF Service


Introduction


Today, in this article let's concentrate on another SilverLight application,  whereby communicating with WCF Service to perform some operation.

Question: What is Typographical Text?
 

In simple terms "SilverLight 5 provides enhancements to define different font styles with help of Typography. It provides different Typographical features like ligatures, stylistic sets and many more".

Let's get this implemented practically for a better idea of this!!! 

Step 1: The complete code of the IService1.cs looks like this.

using System;
using
System.Collections.Generic;
using
System.Linq;

using System.Runtime.Serialization;
using
System.ServiceModel;using System.ServiceModel.Web;
using
System.Text;
namespace
Wcf_Open_Type
{ // NOTE: You can use the "Rename" command on the "Refactor" menu to change the  interface name "IService1" in both code and config file together.

    [ServiceContract]

    public interface IService1

    {
        [OperationContract]

        string typography();
    }

}

Step 2:  The complete code of the Service1.svc.cs looks like this.

using System;
using
System.Collections.Generic;

using System.Linq;
using
System.Runtime.Serialization;

using
System.ServiceModel;
using
System.ServiceModel.Web;

using
System.Text;
namespace Wcf_Open_Type

{

    
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together

       public class Service1 : IService1
       {
           public string typography()
           {
                 return "SilverLight 5...!!! Whoomp..";
             }
       }
}

Step 3: The complete code of the Web.Config looks like this.

<?xml version="1.0"?>
<
configuration>
       <
system.web>
              <
compilation debug="true" targetFramework="4.0" />
       </
system.web>
       <
system.serviceModel>
              <
behaviors>
                     <
serviceBehaviors>
                           <
behavior>
                                  <!--
To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                                  <
serviceMetadata httpGetEnabled="true"/>
                                  <!--
To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
                                  <
serviceDebug includeExceptionDetailInFaults="false"/>

                           </behavior>
                     </
serviceBehaviors>
              </
behaviors>
              <
serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
       </
system.serviceModel>
       <
system.webServer>
              <
modules runAllManagedModulesForAllRequests="true"/>
       </
system.webServer>
</
configuration>

Step 4: The complete code of the Clientaccesspolicy.xml looks like this (To avoid the cross domain problem in SilverLight):

<?xml version="1.0" encoding="utf-8"?>
<
access-policy>
   
<cross-domain-access>
       
<policy>
           
<allow-from http-request-headers="SOAPAction">
               
<domain uri="*"/>
           
</allow-from>
           
<grant-to>
               
<resource path="/" include-subpaths="true"/>
           
</grant-to>
       
</policy>
   
</cross-domain-access>
</
access-policy>

Step 5: The complete code of the MainPage.xaml looks like this:

<UserControl x:Class="Typography_Application.MainPage"
    xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d
="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc
="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable
="d"
    d:DesignHeight="300" d:DesignWidth="400" Loaded
="UserControl_Loaded">

   
<Grid x:Name="LayoutRoot" Background="White">
        
<!--<TextBlock Height="63"
                   HorizontalAlignment="Center"
                   Name="textBlock1"
                   VerticalAlignment="Center"
                   FontFamily="Gabriola"
                   FontSize="34"
                   Width="522"
                   Margin="-63,118,-59,118"
                   Typography.ContextualAlternates="True"
                   Typography.StylisticSet7="True"/>-->

        <!--<TextBlock Height="63"
                   HorizontalAlignment="Center"
                   Name="textBlock1"
                   VerticalAlignment="Center"
                   FontFamily="Gabriola"
                   FontSize="34"
                   Width="522"
                   Margin="-63,118,-59,118"
                   Typography.StylisticSet6="True"/>-->

        <!--<TextBlock Height="63"
                   HorizontalAlignment="Center"
                   Name="textBlock1"
                   VerticalAlignment="Center"
                   FontFamily="Gabriola"
                   FontSize="34"
                   Width="522"
                   Margin="-63,118,-59,118"
                   Typography.Variants="Superscript"/>-->

        <!--<TextBlock Height="63"
                   HorizontalAlignment="Center"
                   Name="textBlock1"
                   VerticalAlignment="Center"
                   FontFamily="Gabriola"
                   FontSize="34"
                   Width="522"
                   Margin="-63,118,-59,118"
                   Typography.Variants="Subscript"/>-->


       
<TextBlock Height="63"
                   HorizontalAlignment="Center"
                   Name="textBlock1"
                   VerticalAlignment="Center"
                   FontFamily
="Gabriola"
                   FontSize
="34"
                   Width="522"
                   Margin
="-63,118,-59,118"
                   Typography.Capitals
="SmallCaps"/>
        <TextBlock Margin="35,28,29,218"  
                   HorizontalAlignment
="Center
                   VerticalAlignment="Center"
                   FontFamily
="Gabriola"
                   FontSize
="34">

        
<Run Typography.Fraction="Slashed" Text="22/12 33/238 " ></Run>
       
</TextBlock>
   
</Grid>
</
UserControl> 

Step 6: The complete code of the MainPage.xaml.cs looks like this:

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;
using
Typography_Application.ServiceReference1;
namespace
Typography_Application
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            data();
        }
        private void typography_Call(object sender, typographyCompletedEventArgs e)
        {
            textBlock1.Text = e.Result;
        }
        public void data()
        {
            objClient.typographyCompleted +=new EventHandler<typographyCompletedEventArgs>(typography_Call);
            objClient.typographyAsync();

        }
        #region
Instance Variables Service1Client objClient = new Service1Client();
        #endregion

    }
}

 Step 7: The output of the Typographical Text @ StylisticSet7 Application looks like this

 Typo1.png

 Step 8:The output of the Typographical Text @ StylisticSet6 Application looks like this

 Typo2.png

 Step 9: The output of the Typographical Text @ Superscript Application looks like this

 Typo3.png

 Step 10: The output of the Typographical Text @ Subscript Application looks like this.

 Typo4.png

 Step 11: The output of the Typographical Text @ SmallCaps Application looks like this:

 Typo5.png

 Step 12: The output of the Typographical Text @ Fraction Application looks like this:

 Typo6.png

I hope this article is useful for you ...I look forward for your comment and feedback....Thanks.

Up Next
    Ebook Download
    View all
    Learn
    View all
    MVC Corporation is consulting and IT services based company.