Silverlight Behavior that Accesses Children

Silverlight Behaviors are a very powerful way to extend a control to do more than in natively does, without having to fully subclass.  I was writing a behavior to attach to a Canvas that would allow for a page turn effect.  In my case I wanted the Canvas to contain other Canvases that it would manipulate.  But I ran into two main dilemmas:

1. The OnAttached event fires before the Children are created.  So how do you manipulate the Children when the control loads?

2.  How do you let the UI Designer tell you which child elements to manipulate?

The answers are quite easy.

Continue reading

Advertisements

Windows Phone 7 Developer Launch

12th is the official launch of Windows Phone 7.  There’s an MSDN Simulcast event available which is a full day of training on writing Windows Phone applications.

There are also free in-person events around the country.  You can learn about them at http://www.msdnevents.com/wp7devlaunch.  Unfortunately the Portland one is already full.

728x90_Banner_WP7DevLaunch

Dislaimer: I think this is a great opportunity, but I also put this on my blog for the chance to win a phone.  Info.

Corner Radius in Silverlight

Maybe everyone else already knew this, but I sure didn’t.  I knew CornerRadius can be used on a Border to round corners.  For example, the following code creates a rounded corner rectangle.

<Border  Height="135" HorizontalAlignment="Left" Width="347" CornerRadius="20" Background="#FF1322D1"></Border>

image

But what’s not obvious is that CornerRadius actually accepts a comma-delimited list (like Margin does) and lets you set the radius of each corner.

<Border Height="135"HorizontalAlignment="Left"Width="347"CornerRadius="20,40,0,5"Background="#FF1322D1"></Border>

image

 

I guess the designers of Blend didn’t realize this either, because while Margin has 4 boxes for entering values, CornerRadius is just one field:

image