Using VS Snippets to Add DependencyProperties and Attached DependencyProperties

It can be a little tedious to type in everything that you need to define a DependencyProperty but you can use VS 2008’s snippets to make is easy. The snippets are designed to work with WPF, but they can be made to work with Silverlight with one small change. First, you need to insert the…

1

Using an Attached DependencyProperty to Implement Pixel Snapping as an Attached Behavior

In a previous post, I introduced the Snapper element, which is a UserControl subclass that snaps its Content to an integer pixel. Now I’ll show how to implement snapping as an attached behavior using a custom attached DependencyProperty. To use the Snapper element, you put it into your tree, and “wrap” the element that you want…

7

Navigation with Animated Transition Effects

One of the common things that developers want to do is to navigate between pages of their application. Once they have that, then they want to make the transitions look pretty. The attached project (see below) show how to do use a TransitionControl to do both. The TransitionControl is extensible, so you can even write your…

8

DiscreteSlider – Adding Functionality with a Simple Control Subclass

How do you prevent the Slider from returning “ugly” values, and get it to “snap” to only the values that you want, such as integers, or multiples of a certain step value such as 0.125? One way to do this is to override OnValueChanged, but it helps to understand how that mechanism works. Below is an example of subclassing Slider to add…

6

Using Popup to create a Dialog class

Presenting a dialog to the user is a common task for many applications. Silverlight 2 does not have a Dialog class, but it is possible to use the Popup class to create a very credible dialog. My Dialog class can’t leave the Silverlight plugin–for that you would have to use Javascript interop to create a new Silverlight…

14

Layout Events – SizeChanged and LayoutUpdated

Executive Summary: Most of the time, SizeChanged is the right event to use, and LayoutUpdated is the wrong event.  The Silverlight 2 layout system offers two events: SizeChanged and LayoutUpdated. They look the same…here is how they are hooked up in C#: public Page() {     InitializeComponent();       LayoutRoot.SizeChanged += LayoutRoot_SizeChanged;     LayoutRoot.LayoutUpdated += LayoutRoot_LayoutUpdated;…

2

Pixel Snapping – the Snapper Element

What is pixel snapping? Snapping in general usually refers to allowing a property to take discrete as opposed to continuous values. In Silverlight, values such as Width, Height, Canvas.Left and Canvas.Top are of type double and not restricted to integer values, even though they refer to pixels. It is easy to consider how a 10…

2

Why I Don’t Like Canvas

In Silverlight 1.0, the only container element was Canvas. In Silverlight 2, there are a number of other layout containers, such as Grid, Border and StackPanel, and you can also make your own. Silverlight 2 applications can be completely layout-based and not rely on absolute positioning at all. Of course, you can still use Canvas. But should you?…

8