WPF

There are 7 entries for the tag WPF
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

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)

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)

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)

Binding to Nullable Values in XAML

I stumbled upon some behavior awhile back that struck me as odd.  I had a nullable property in my ViewModel that I was binding to in Silverlight, but I found that whenever the value was cleared out by the user, the property setter was not called. I narrowed it down to a simple application that has properties for Name and Age, as follows: 1: public string Name 2: { 3: ...

posted @ Wednesday, July 9, 2008 2:07 PM | Feedback (15)

Property Changed Events

When creating a class that can be used with data binding, you have to implement the INotifyPropertyChanged interface.  This interface requires that you have an event for PropertyChanged, specifying PropertyChangedEventArgs that provide the property name that was changed. Here’s what I mean: 1: public class Person : System.ComponentModel.INotifyPropertyChanged 2: { 3: private string _name; 4:  ...

posted @ Thursday, June 19, 2008 1:47 PM | Feedback (4)