Sunday, March 8, 2009

Adding RTL Support to Silverlight Using SilverlightRTL Library – Part 1

In the previous post, options to display Arabic text with Silverlight has been explored. In this post we will explore how to use the Open Source SilverlightRTL library available from http://www.codeplex.com/silverlightRTL to add RTL support for Silverlight Applications.

Using SilverlightRTL From Visual Studio
First you will need to download the bits from CodePlex site, you can either download the latest release from http://silverlightrtl.codeplex.com/Release/ProjectReleases.aspx or if you want the most recent update, you can download the source code from http://silverlightrtl.codeplex.com/SourceControl/ListDownloadableCommits.aspx. I recommend download the source code, so you get the latest updates, and you can debug into the source code if you happen to face any problem.
Now add reference to the BidiControls assembly or the project if you are using the source code directly from your project.
The next step is to add a namespace reference to your XAML file. Please note that you need to compile the project first if you are using project reference or intellisense to work. The XMLNS declaration should look like the following snippet:

   1: clr-namespace:System.Windows.BidiControls;assembly=BidiControls




And Visual Studio screen should look like the following figure:

namespace



Now you can declare a BIDI control by prefixing the control with bidi: namespace, for example:





   1: <bidi:TextBlock Text="أهلا عالم" FontSize="18" />




Using SilverlightRTL from Blend

Firstyou will need to add reference to the BidiControls.dll assembly or the System.Windows.BidiControls project. To add a control You can open the “Asset Library” at the bottom of the Toolbox. Select “Custom Controls” tab. You should find the BIDI controls available. You can search for a specific control using search box. The following screenshot shows that



blend_add



Please stay tuned. I will post more about the specific controls implemented, how you can use and style them, and how the controls were implemented.