
{"id":1048,"date":"2012-08-09T12:46:56","date_gmt":"2012-08-09T16:46:56","guid":{"rendered":"http:\/\/www.ikriv.com\/blog\/?p=1048"},"modified":"2012-08-09T12:46:56","modified_gmt":"2012-08-09T16:46:56","slug":"silverlight-clipping-fun","status":"publish","type":"post","link":"https:\/\/ikriv.com\/blog\/?p=1048","title":{"rendered":"Silverlight Clipping Fun"},"content":{"rendered":"<p>While Silverlight animation performance may be better than WPF, its support for clipping is definitely inferior.<\/p>\n<p>First off, there is no <code>ClipToBounds<\/code> property. If you want your canvas to clip its content, you need <a href=\"http:\/\/www.codeproject.com\/Articles\/36495\/Silverlight-ClipToBounds-Can-I-Clip-It-Yes-You-Can\">some extra code<\/a>.<\/p>\n<p>Then, it turns out that a <code>TextBlock<\/code> inside a canvas won&#8217;t clip itself. Basically, the &#8220;Width&#8221; property is ignored: the text will tak<img decoding=\"async\" src=\"http:\/\/www.ikriv.com\/sl\/clip\/screenshot.png\" alt=\"Screen shot\" \/>e as much space as it sees fit. You can, however, tame a <code>TextBlock<\/code> by placing it inside a <code>Border<\/code>. This also gives a benefit of vertical alignment, that bare <code>TextBlock<\/code> cannot do.<\/p>\n<p><a href=\"http:\/\/www.ikriv.com\/dev\/sl\/clip\/\">Sample<\/a><\/p>\n<p><a href=\"http:\/\/www.ikriv.com\/dev\/sl\/clip\/\"><img decoding=\"async\" src=\"http:\/\/www.ikriv.com\/dev\/sl\/clip\/screenshot.png\" alt=\"Screenshot\" \/><\/a><\/p>\n<p>The sample is generate by this code:<\/p>\n<pre style=\"font-family: Consolas; font-size: 13; color: black; background: white;\"><span\n        style=\"color:blue;\">&lt;<\/span><span style=\"color:#a31515;\">Border<\/span><span\n        style=\"color:red;\">&nbsp;Width<\/span><span style=\"color:blue;\">=&quot;300&quot;<\/span><span\n        style=\"color:red;\">&nbsp;Height<\/span><span style=\"color:blue;\">=&quot;300&quot;<\/span><span\n        style=\"color:red;\">&nbsp;BorderBrush<\/span><span style=\"color:blue;\">=&quot;Blue&quot;<\/span><span\n        style=\"color:red;\">&nbsp;BorderThickness<\/span><span style=\"color:blue;\">=&quot;1&quot;&gt;<\/span>\n<span style=\"color:#a31515;\">&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color:blue;\">&lt;<\/span><span\n        style=\"color:#a31515;\">Canvas<\/span><span style=\"color:blue;\">&gt;<\/span>\n<span style=\"color:#a31515;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color:blue;\">&lt;<\/span><span\n        style=\"color:#a31515;\">Border<\/span><span style=\"color:red;\">&nbsp;Width<\/span><span\n        style=\"color:blue;\">=&quot;50&quot;<\/span><span style=\"color:red;\">&nbsp;BorderBrush<\/span><span\n        style=\"color:blue;\">=&quot;Black&quot;<\/span><span style=\"color:red;\">&nbsp;BorderThickness<\/span><span\n        style=\"color:blue;\">=&quot;1&quot;<\/span><span style=\"color:red;\">&nbsp;Canvas.Left<\/span><span\n        style=\"color:blue;\">=&quot;30&quot;<\/span><span style=\"color:red;\">&nbsp;Canvas.Top<\/span><span\n        style=\"color:blue;\">=&quot;30&quot;&gt;<\/span>\n<span style=\"color:#a31515;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color:blue;\">&lt;<\/span><span\n        style=\"color:#a31515;\">TextBlock<\/span><span style=\"color:red;\">&nbsp;Text<\/span><span\n        style=\"color:blue;\">=&quot;This&nbsp;TextBLock&nbsp;is&nbsp;50&nbsp;pixels&nbsp;wide&quot;&nbsp;\/&gt;<\/span>\n<span style=\"color:#a31515;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color:blue;\">&lt;\/<\/span><span\n        style=\"color:#a31515;\">Border<\/span><span style=\"color:blue;\">&gt;<\/span>\n\n<span style=\"color:#a31515;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color:blue;\">&lt;<\/span><span\n        style=\"color:#a31515;\">Border<\/span><span style=\"color:red;\">&nbsp;Width<\/span><span\n        style=\"color:blue;\">=&quot;300&quot;<\/span><span style=\"color:red;\">&nbsp;Height<\/span><span\n        style=\"color:blue;\">=&quot;100&quot;<\/span><span style=\"color:red;\">&nbsp;BorderBrush<\/span><span\n        style=\"color:blue;\">=&quot;Brown&quot;<\/span><span style=\"color:red;\">&nbsp;BorderThickness<\/span><span\n        style=\"color:blue;\">=&quot;1&quot;<\/span><span style=\"color:red;\">&nbsp;Canvas.Left<\/span><span\n        style=\"color:blue;\">=&quot;30&quot;<\/span><span style=\"color:red;\">&nbsp;Canvas.Top<\/span><span\n        style=\"color:blue;\">=&quot;80&quot;&gt;<\/span>\n<span style=\"color:#a31515;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color:blue;\">&lt;<\/span><span\n        style=\"color:#a31515;\">TextBlock<\/span><span style=\"color:red;\">&nbsp;Text<\/span><span\n        style=\"color:blue;\">=&quot;Centered&nbsp;text&quot;<\/span><span style=\"color:red;\">&nbsp;HorizontalAlignment<\/span><span\n        style=\"color:blue;\">=&quot;Center&quot;<\/span><span style=\"color:red;\">&nbsp;VerticalAlignment<\/span><span\n        style=\"color:blue;\">=&quot;Center&quot;&nbsp;\/&gt;<\/span>\n<span style=\"color:#a31515;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color:blue;\">&lt;\/<\/span><span\n        style=\"color:#a31515;\">Border<\/span><span style=\"color:blue;\">&gt;<\/span>\n<span style=\"color:#a31515;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span>\n<span style=\"color:#a31515;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color:blue;\">&lt;<\/span><span\n        style=\"color:#a31515;\">TextBlock<\/span><span style=\"color:red;\">&nbsp;Width<\/span><span\n        style=\"color:blue;\">=&quot;10&quot;<\/span><span style=\"color:red;\">&nbsp;Text<\/span><span\n        style=\"color:blue;\">=&quot;This&nbsp;TextBlock&nbsp;is&nbsp;10&nbsp;pixels&nbsp;wide&quot;<\/span><span\n        style=\"color:red;\">&nbsp;Canvas.Left<\/span><span style=\"color:blue;\">=&quot;150&quot;<\/span><span\n        style=\"color:red;\">&nbsp;Canvas.Top<\/span><span style=\"color:blue;\">=&quot;250&quot;&nbsp;\/&gt;<\/span>\n<span style=\"color:#a31515;\">&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color:blue;\">&lt;\/<\/span><span\n        style=\"color:#a31515;\">Canvas<\/span><span style=\"color:blue;\">&gt;<\/span>\n<span style=\"color:blue;\">&lt;\/<\/span><span style=\"color:#a31515;\">Border<\/span><span\n        style=\"color:blue;\">&gt;<\/span>\n<\/pre>\n<p><a style=\"display:none\" href=\"http:\/\/www.codeproject.com\/script\/Articles\/BlogFeedList.aspx?amid=1181663\" rel=\"tag\">CodeProject<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>While Silverlight animation performance may be better than WPF, its support for clipping is definitely inferior. First off, there is no ClipToBounds property. If you want your canvas to clip <a href=\"https:\/\/ikriv.com\/blog\/?p=1048\" class=\"more-link\">[&hellip;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":""},"categories":[4,19],"tags":[],"class_list":["entry","author-ikriv","post-1048","post","type-post","status-publish","format-standard","category-hack","category-silverlight"],"_links":{"self":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1048","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1048"}],"version-history":[{"count":0,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1048\/revisions"}],"wp:attachment":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1048"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1048"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1048"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}