Sunday, August 02, 2009

Clip a TextBlock in SilverLight

One of the things that you may need to do in SilverLight is to limit the display area of a TextBlock, and you can do that using the Clip property, there are two ways to do that.

1. From the XAML

<TextBlock x:Name="tbExtension" Width="130" Height="30" Foreground="Black" Canvas.Left="5">
<TextBlock.Clip>
<RectangleGeometry Rect="0, 0, 130, 30"/>
</TextBlock.Clip>
</TextBlock>

2. From the code behind

tbExtension.Clip = new RectangleGeometry() {
Rect = new Rect(0, 0, width, height)
};

2 comments:

Rusty said...

Nice tip!

Juanpa said...

Great, I used it in a Border in order to dissapear the textblock when it moves

Running Proxmox Inside Hyper-V on Windows 11: Nested Virtualization Lab Setup

I have a good PC at home with an Intel i9 12th Gen processor, 96GB RAM, and 1TB of unused disk storage. It’s our family PC for everyday use,...