Skip to main content Skip to footer

RTL-ing ComponentOne RichTextBox

Microsoft Visual Studio LightSwitch supports localizing application in more than 40 languages by setting the Application Culture. So for example, if we are using an English VS LightSwitch, we can create applications in any of the 40 languages including RightToLeft languages like Arabic, Hebrew etc. The C1RichTextBox for LightSwitch automatically switches to RTL when the culture is set. However, this blog deals with the implementation where only the C1RichTextBox layout needs to be changed instead of the entire application.

RTL-ing Layout of C1RichTextBox

Changing the layout of only C1RichTextBox for LightSwitch is very easy. We simply need to get the RichTextBox control in the ControlAvailable event and set the FlowDirection to RightToLeft. The C1RichTextBox would look as follows : Img_RichTextBox Here is the code :

IContentItemProxy proxy = this.FindControl("SourceText");  
proxy.ControlAvailable += (s,e1)=>  
{  
            if (e1.Control is C1RichTextBox)  
            {  
                rtb = e.Control as C1RichTextBox;  
                rtb.FlowDirection = System.Windows.FlowDirection.RightToLeft;  
            }  
};

RTL-ing Collection C1RichTextBox

Things become different when C1RichTextBox is used inside the collection of say C1FlexGrid. The trick here is to use the Ready property to ensure that the cells are created, then manipulate each RTB control separately. First, add these using statements:

using Microsoft.LightSwitch.Threading;  
using C1.LightSwitch.FlexGrid.Presentation.Controls;  
using C1.LightSwitch.RichTextBox.Presentation.Controls;  
using System.Windows.Controls;  
using System.Windows;

Then handle the ControlAvailable event like this:

partial void FlexibleEmployeesGrid_Created()  
{  
    this.FindControl("C1FlexGrid").ControlAvailable += FlexibleEmployeesGrid_ControlAvailable;  
}  

void FlexibleEmployeesGrid_ControlAvailable(object sender, ControlAvailableEventArgs e)  
{  
    LSFlexGrid flex = (LSFlexGrid)e.Control;  
    flex.Ready = delegate(LSFlexGrid grid)  
    {  
        Dispatchers.Main.BeginInvoke(() =>  
        {  
            foreach (var rtb in grid.Cells.Children  
                .OfType<Border>()  
                .Where(b => b.Child is C1RichTextBox)  
                .Select(b => ((C1RichTextBox)b.Child).Control as Control))  
            {  
                rtb.FlowDirection = FlowDirection.RightToLeft;  
            }  
        });  
    };  
}

Resulting in RTL Cells: image001

Summary

Today’s C1RichTextBox enables a ton of great new scenarios, and makes building applications even easier. If you don’t already have ComponentOne Studio for LightSwitch, you can sign-up for a free trial and start using all of the above features today.

MESCIUS inc.

comments powered by Disqus