|
|
|
|
|
|
|
Technologies:
.NET 3.0 and 3.5, Silverlight,Visual C# .NET
|
|
Total downloads :
|
|
|
Total page views :
|
1493
|
|
Rating :
|
|
0/5
|
|
This article has been rated :
|
0 times
|
|
|
|
Similar ArticlesMost ReadTop RatedLatest
|
|
Related EbooksTop Videos
|
|
|
Description
|
|
Author Jeff Scanlon assumes you’re already comfortable with the basics of .NET coding and with WPF, and they help you build on your existing knowledge to make your journey to Silverlight 2 proficiency as quick and painless as possible.
|
|
|
|
|
|
|
|
|
|
|
|
|
Today, I am going to show you guys, "How to you Embedded Fonts" in your Silverlight2 applications.
Silverlight2 has a very rich library for creating RIA (Rich Internet Applications) but has less features and functionalities compared to its father WPF(Windows Presentation Foundation). This is so because, Silverlight is a browser plugin which gets downloaded to the client machine, the first time a user access any web page having Silverlight content. So for making the download experience smooth, the Silverlight plugin/player has been packed with the minimum and most required features and functionalities, so that its size is less, and it can be downloaded to the client computer ASAP. Once, the plugin has been installed, the user can access the Silverlight pages without any interruption. Currently the Silverlight2 plugin has a download size of 4.6MB.
This is the reason why, Silverlight2 is not provided with a wide variety of Fonts. By Default, a Silverlight2 application supports and provides 9 fonts, mentioned below:

So for using Fonts other than than the ones specified above, we would need to embed it into our application assembly as a "Resource".
We can use the embedded font either using "Code" or "Markup".
For either of the way, first we need to add the desired font into our Silverlight2 application project. I am using a freely available font named "A Cut Above the Rest". You can easily find it and several other free fonts on the following website - http://www.urbanfonts.com/free-fonts.htm
To add the font file to your project, perform the below steps:
- Right Click your Silverlight application project, and choose "Add", then "Add Existing Item" menu Item. Then select the font file(with .TTF extension) to be used.
- After the font file gets added to your project, Right-click on the file and click Properties. On the properties window, set the "Build Action" property to "Resource". Setting this property will embed your newly added font file to your application assembly as a binary resource, which can later be used for the usage.

So, now we are done and ready to use our newly added font "A Cut Above the Rest". Below example uses XAML Markup to set the new font "A Cut above the Rest" to a TextBlock element.
<TextBlock x:Name="MyLabel" Foreground="Blue" FontFamily="ACUTATR_.TTF#A Cut Above the Rest" FontSize="25">
| The above example has a XAML Markup having the following syntax in the "FontFamily" property: "FontFileName#FontName". For our font, the file name is "ACUTATR_.TTF" and the font name is - "A Cut Above the Rest".
Now, the second way to use embedded font in Silverlight2 application is to use Code. As I work in C#, so I am providing a C# example:
using System.Windows.Resources;
/*Use Embedded Font - A Cut Above the Rest*/
StreamResourceInfo sri = Application.GetResourceStream(new Uri("PracticeEmbeddedFonts;component/ACUTATR_.TTF", UriKind.Relative));
MyLabel.FontSource = new FontSource(sri.Stream);
MyLabel.FontFamily = new FontFamily("A Cut Above the Rest");
| Here, 3 classes are used to retrieve the font from the Font file.
- StreamResourceInfo
- Application
- FontSource
In the above code, the font is retrieved from the assembly as a Resource by using the "Application.GetResourceStream()" method. It accepts 2 arguments. The first argument here follow the following format :- "AssemblyName:component/FontFileName.TTF"
After retrieving the font from the assembly, we can assign it to the control we want to, by first assigning the "FontSource" property with our Font Resource stream object's Stream property. Then we assign the name of the font from that font file i.e., "A Cut Above the Rest".
For the above code to work, an important assembly namespace reference will need to be made i.e., - "using System.Windows.Resources;
After successfully coding the application, our TextBlock will have a font like shown in the below picture:

NOTE :- Not all the fonts that are on the Internet are available for free distribution. For many of them you will need to purchase a license from the owner. So please take this note in mind, while using any font.
|
|
|
Login
to add your contents and source code to this article
|
|
|
|
|
|
|
|
|
|
|
|
Deepak Pathak
Currently working in Espire Infolabs Pvt. Ltd., New Delhi as a Snr. Software Engineer. I m currently working on ASP.NET, XML Web Serivces and C#. I love Microsoft Techonolgies and currently have a keen interest in SOA and its current applications through WCF, Silverlight. I am currently learning LINQ, jQuery and ADO.NET Entity Framework.
|
|
|
|
|
|
|
|
|
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional
consulting company, our consultants are well-known experts in .NET and many of them
are MVPs, authors, and trainers. We specialize in Microsoft .NET development and
utilize Agile Development and Extreme Programming practices to provide fast pace
quick turnaround results. Our software development model is a mix of Agile Development,
traditional SDLC, and Waterfall models.
|
|
Click here to learn more about C# Consulting. |
|
|
|
|
|
|
|
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon.
Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees.
As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
|
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
|
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
|
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today. With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications. Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
|
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or
application via a range of API's. Learn More about our API connections.
|
Microsoft Visual Studio 2010
Microsoft Visual Studio 2010 offers more to developers than any other
Visual Studio release. Work more productively and collaboratively-with
greater control over your work at every step. The Beta 2 can give you a
head start on achieving efficiency.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|