Click here to Skip to main content
13,346,487 members (67,382 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked
Posted 5 Sep 2010

Who’s the Boss

, 5 Sep 2010
Rate this:
Please Sign up or sign in to vote.
Who's the boss?

“With great power comes great responsibility” - Uncle Ben (Spider-Man)

In the previous article, I covered the TimeslotPanel… This panel is VERY flexible and allows us to arrange items based on timeslots. This begs the question… Who controls this panel?

Design a DateRangeSpinner

As a control, the DateRangeSpinner is VERY simple. It has 2 buttons (Next and Previous) that will adjust the DateRange based on the selected constraint (Day = 1, Week = 7, etc.) and a display text that should show the current DateRange in a human readable format. To use the DateRangeSpinner is very easy, first create a spinner:

<rg:DateRangeSpinner x:Name="dateRangeSpinner" DateRangeConstraints="Week" />

And then to use it:

<rg:TimeslotPanel ShowGridLines="True" 

      DateRange="{Binding ElementName=dateRangeSpinner, Path=DateRange, Mode=TwoWay}">

As the range changes, the TimeslotPanel will re-adjust!!!

What Have I Learned?

Why Not Derive from Spinner?

The Silverlight toolkit has a cool base control called a Spinner! It would have made sense to derive from this control (and in the future I might) but for now I did not want to force a dependency on any external libraries (especially because I am targeting both WPF and Silverlight).


One of my design goals was theme-ability… Both the previous and next buttons are style-able.

        <Style TargetType="{x:Type Button}">
            <Setter Property="Background" Value="Blue" />

Making WPF Controls Work in Silverlight

By default, a new control created using the WPF template has a static constructor:

static DateRangeSpinner()
	new FrameworkPropertyMetadata(typeof(DateRangeSpinner)));

“The DefaultStyleKeyProperty, as the name suggests, is used to tell WPF about the key that should be used to perform the style lookup. By overriding this property as shown in the preceding example, you are telling WPF to use the control’s type as the key for its default style. If you skip this step, WPF will have no way to discover the default style of the control (defined in generic.xaml in the control’s assembly).”

To allow this code to work in Silverlight, change it to the following:

public DateRangeSpinner()
    DefaultStyleKey = typeof(DateRangeSpinner);

Also Read


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

South Africa South Africa
No Biography provided

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 6 Sep 2010
Article Copyright 2010 by rudigrobler
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid