I’ve always liked attached properties… so much so that a couple of years ago I created a series of generic classes to simplify the process of creating custom attached properties.

Attached Properties – a review:

  • External control interactions — like the Grid.Row attached property.
  • Basic info storage — just like the Tag property.
  • Behaviors — changing properties and behaviors of the parent control.
  • Bindings — to achieve custom bindings between UI controls.
  • If you use XAML, you use attached properties whether you realize it or not.

Creating a custom attached property only takes a few lines of code. Many declarative ...

 

In a recent project I was working on I wanted to create a slideshow or automated dashboard that would show several slides at a given interval. Telerik has a fantastic RadTransitionControl that has some very nice transition effects but doesn’t automatically change the slides. I wanted a generic way of automating this so I went with some attached properties.

 

Here is the declaration of the three attached properties:

 1:  public  static  readonly DependencyProperty IntervalProperty =
 2:     DependencyProperty.RegisterAttached("Interval",  typeof(TimeSpan),  typeof(SelectorSlideShow),  new PropertyMetadata(new TimeSpan(0, 0, 0, 5), IntervalChanged));
 3:   
 4:  public  static  readonly DependencyProperty ...