Click here to Skip to main content
12,820,914 members (34,073 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


3 bookmarked
Posted 10 Aug 2012

Silverlight Clipping Fun

, 10 Aug 2012 Apache
Rate this:
Please Sign up or sign in to vote.
Silverlight's support for clipping is definitely inferior.

While Silverlight animation performance may be better than WPF, its support for clipping is definitely inferior.

First off, there are no ClipToBounds property. If you want your canvas to clip its content, you need some extra code.

Then, it turns out that a TextBlock inside a canvas won’t clip itself. Basically, the “Width” property is ignored: the text will take as much space as it sees fit. You can, however, tame a TextBlock by placing it inside a Border. This also gives a benefit of vertical alignment, that bare TextBlock cannot do.



The sample is generated by this code:

<Border Width="300" Height="300" 
BorderBrush="Blue" BorderThickness="1">
        <Border Width="50" BorderBrush="Black" 
        BorderThickness="1" Canvas.Left="30" Canvas.Top="30">
            <TextBlock Text="This TextBLock is 50 pixels wide" />

        <Border Width="300" Height="100" 
        BorderBrush="Brown" BorderThickness="1" 
         Canvas.Left="30" Canvas.Top="80">
            <TextBlock Text="Centered text" 
            HorizontalAlignment="Center" VerticalAlignment="Center" />
        <TextBlock Width="10" 
        Text="This TextBlock is 10 pixels wide" Canvas.Left="150" 
         Canvas.Top="250" />


This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


About the Author

Ivan Krivyakov
Technical Lead Thomson Reuters
United States United States
Ivan is a hands-on software architect/technical lead working for Thomson Reuters in the New York City area. At present I am mostly building complex multi-threaded WPF application for the financial sector, but I am also interested in cloud computing, web development, mobile development, etc.

Please visit my web site:

You may also be interested in...

Comments and Discussions

GeneralMy vote of 4 Pin
Christian Amado10-Aug-12 4:09
memberChristian Amado10-Aug-12 4:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 10 Aug 2012
Article Copyright 2012 by Ivan Krivyakov
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid