How to: Create a Simple Binding, reviewing the article on MSDN

An example article, if you read the article for Framework 4.0, would be: How to: Create a Simple Binding, first of all tere is a mention of a SDKSample.  But there is no sample on the page.  That is because the sample is included on the article for Framework 3.0 and Framework 3.5, which you have to use the drop down next to Framework 4.0 to find.  Then it is in the middle of that page. 

It’s a typo, but can waste your time if you try to work with the article as written. 

Then when you get the sample running, if you aren’t careful the sample will need to be unblocked because it is downloaded from the internet, and the files are unsigned.

Ok, the “How To: Create a Simple Binding” shows the necessary XAML, but neglects to show the class.  How does the class work with the XAML?

First of all the class isn’t a code behind module that you might have used in earlier study or exploration, it is simply a class.  In the example

xmlns:src=”clr-namespace:SDKSample”

is one of the lines of XAML, and can misbehave.  First of all the letters src, as I have mentioned in another blog, could be replaced with any word, even pineapple.

When you use the form: image, if all goes well you will see the objects in the related class file in a little intellisense file, like what is in the image.

The sample code does not come with a SLN file that will automatically load the files, it only comes with a CSPROJ. In this case, make sure to unblock the files, and load the project into your Visual Studio environment, make sure to load the csproj, once it loads in, all the other files load in as well and your references are set-up nicely.  If I recall correctly, the upgrade wizard runs as well since the version for the files are Framework 3.0.

The class implements the following class and interface.  The event INotifyPropertyChanged, which has a single event: PropertyChanged.

ClassDiagram1

In the PersonName property, I changed the Set to show the length of the string:

public string PersonName
{
get { return name ; }
set
{
name = "Length " + value.Length;
// Call OnPropertyChanged whenever the property is updated
OnPropertyChanged("PersonName");
}
}

Hope this helps. Smile