Text Trimming in Silverlight 4 Using VS 2010 Beta


 

Introduction

In Silverlight 4, a property called TextTrimming is added to TextBlock, which will help the TextBlock to Trim up to defined width. In this article we will see how this feature works.

Creating Silverlight Project

Fire up Visual Studio 2010 and create a new Silverlight Application Project. Name it as TextTrimmingInSL4.

We will have some TextBlocks to see how TextTrimming works in Silverlight 4.

The above TextBlock is a normal TextBlock whose Width is set to Auto by default.

In design view it would look like following.

Now we will have another TextBlock whose Width is set to 290.

In design view the above TextBlock it looks like following.

Now we will have a TextBlock whose Width is set to 150 and TextTrimming property is set to “WordEllipsis”.

In design view it would look like following.

Let’s run the application and resize the Browser Window.

You will see The TextBlock which has the TextTrimming property set to “WordEllipsis” will continue to trim if the width is less than it’s set value.

Without Resize the TextBlocks View.

With Resize the TextBlocks View.

Hope this article helps.

Advertisements