October 2008 Blog Posts

Silverlight Control Template Doesn’t Get Applied

This is something that has bitten me several times, so I thought I’d write it down.  Maybe I’ll remember, and maybe I’ll help others when they hit this too. The scenario happens when you want to create a new control that can have a template applied to it.  Let’s start with this control definition: 1: using System; 2: using System.Windows.Controls; 3: using System.Windows.Markup; 4:  ...

posted @ Wednesday, October 29, 2008 6:15 PM | Feedback (6)

Binding Converters - VisibilityConverter

One of the reasons why the ViewModel pattern is so powerful in Silverlight and WPF is because Binding Converters can do so much.  As we saw in HelloWorld.ViewModel, a ViewModel can expose a boolean property that is consumed as a Visibility value for controls.  This requires some glue to convert the boolean to the necessary enum, and that’s where our VisibilityConverter comes in.  If you want to see this in action, go check out the sample code, but here’s how the VisibilityConverter works. In order to create any binding converter, you can start off by creating a class that...

posted @ Monday, October 27, 2008 9:58 PM | Feedback (1)

HelloWorld.ViewModel – Code & Running App

I just updated my HelloWorld.ViewModel post from earlier today to include the full source code as well as a running app (and a screen shot). Running app here. Source code here.

posted @ Monday, October 27, 2008 8:46 PM | Feedback (3)

HelloWorld.ViewModel

A few folks asked me to provide a ViewModel sample of some sort.  I thought this was a great idea, since I don’t know that I had seen a straight-forward ViewModel sample yet.  So here it is: HelloWorld.ViewModel!   Click the image to view the Silverlight sample live. Let’s start out by looking at the code for the ViewModel class, since that’s the file that I authored first. 1: using System; 2: using System.ComponentModel; ...

posted @ Monday, October 27, 2008 11:08 AM | Feedback (14)

ViewModel Pattern

When I was at BIG, I created what I called the Extended MVP pattern.  I built a framework that was used on multiple projects for managing the presentation layer as well as validation.  I’m still very happy with what I created, and my teams at BIG are still pleased with those applications as well.  In fact, I just learned that they were looking into using the pattern within a Silverlight project they’re doing a proof of concept for.  I mentioned the ViewModel pattern to them, suggesting they use it instead of using the MVP approach.  When asked for more information,...

posted @ Tuesday, October 21, 2008 4:31 PM | Feedback (5)

Silverlight 2 RTW

Tonight, Silverlight 2 is being released to the web (RTW).  This release marks an important milestone for .NET developers, probably more so than most realize. Silverlight 2 provides a browser control that can host .NET assemblies.  If you’ve been living under a rock, or if you just haven’t been following the Silverlight story, this is news to you; but chances are, you’ve heard this before.  But if this doesn’t make you jump up and down with excitement, then you might need to sit back and really think about what Silverlight 2 can do for you.  And then jump and...

posted @ Tuesday, October 14, 2008 12:44 AM | Feedback (0)

Silverlight 2 Gotcha - Tab Navigation in a Popup, Take 2

After I posted about how to regain tab navigation in a popup, Ian commented that the workaround had some flaws.  First, he lost intellisense inside the <UserControl> and second, which is more painful, he could not refer to any controls inside the child <UserControl> from the page's code-behind. Well, I found a more suitable workaround.  Instead of using a <UserControl> to set the TabNagation, you can use a <ContentControl> instead.  Here's the updated workaround code: 1: <UserControl x:Class="PopupTabbing.Page" 2: ...

posted @ Thursday, October 9, 2008 10:54 AM | Feedback (3)

INotifyPropertyChanged - Extension Methods

One of the approaches I've tried using to combat the PropertyChangedEventHandler nuisance is an extension method on INotifyPropertyChanged.  Actually, a pair of them.  One accepts a single property name and the other accepts a param array of property names, so that events can be fired for multiple events succinctly. 1: /// <summary> 2: /// Raise the specified PropertyChangedEventHandler for the sender 3: /// and property name, but only when the handler is not null ...

posted @ Tuesday, October 7, 2008 9:05 PM | Feedback (5)

Silverlight 2 Gotcha - Tab Navigation in a Popup

While building an app in Silverlight 2 RC0, I was trying to use a Popup to display a login form.  Pretty basic form: Username, Password, button.  But I immediately noticed that I could not hit Tab to move from one field to the next. Here's some XAML that demonstrates the problem: 1: <UserControl x:Class="PopupTabbing.Page" 2: xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4:...

posted @ Tuesday, October 7, 2008 8:44 PM | Feedback (3)

INotifyPropertyChanged -- Searching for a Better Way

I've been fiddling with different approaches for implementing INotifyPropertyChanged.  I blogged one approach awhile back, declaring my unhappiness with the pattern.  Neil Mosafi also talked about how INotifyPropertyChanged might be an anti-pattern.  I keep searching for a better way. At last night's Nerd Dinner, Brian Henderson was talking to Glenn Block and me about this problem.  He suggested a language feature of some sort, with perhaps the feeling of generics.  He mentioned that there really isn't anything to make properties easier, other than the automatic properties of C#, but those aren't very flexible. I crafted a syntax that...

posted @ Tuesday, October 7, 2008 5:02 PM | Feedback (2)