Data Binding Demo Home
This page is specific to:.NET Framework Version:3.03.54.0
Windows Presentation Foundation Samples
Data Binding Demo

This sample creates a product listing application that allows users to enter items for sale. This sample demonstrates the following data binding concepts:

  • The binding object

  • Data context

  • Data templates

  • Property change notifications

  • Validation

  • Conversion

  • Data triggers

  • Multibinding

  • Binding to sub-properties

  • Master-Detail paradigm

  • Collection view source

  • Grouping

  • Sorting

  • Filtering

This sample demonstrates a specific feature of the Windows Presentation Foundation (WPF) and, consequently, does not follow application development best practices. For comprehensive coverage of Windows Presentation Foundation (WPF) and Microsoft .NET Framework application development best practices, refer to the following as appropriate:

Accessibility - Accessibility Best Practices

Security - Windows Presentation Foundation Security

Localization - WPF Globalization and Localization Overview

Download sample

Building the Sample

  • Install the Windows Software Development Kit (SDK) and open its build environment command window. On the Start menu, point to All Programs, Microsoft Windows SDK, and then click CMD Shell.

  • Download the sample, usually from the software development kit (SDK) documentation, to your hard disk drive.

  • To build the sample from the build environment command window, go to the source directory of the sample. At the command prompt, type MSBUILD.

  • To build the sample in Microsoft Visual Studio, load the sample solution or project file and then press CTRL+SHIFT+B.

Running the Sample

  • To run the compiled sample from the build environment command window, execute the .exe file in the Bin\Debug or Bin\Release folder contained under the sample source code folder.

  • To run the compiled sample with debugging in Visual Studio, press F5.

Community Content

Sample doesn't build in VS2008.
Added by:durgesh dwivedi
Error 1 Specified cast is not valid. C:\Users\Me\Desktop\DataBindingLab\csharp\AddProductWindow.xaml 108 25 databindinglab
The sample raises a error into the designer. Using VS 2008
Added by:Thomas Lee
The HOL exercise 1 works fine, but into the designers this code raise "Specified cast is not valid":

<ComboBox.IsEnabled>
<MultiBindingConverter="{StaticResource specialFeaturesConverter}">
<Binding Path="CurrentUser.Rating"
Source="{x:Static Application.Current}"/>
<Binding Path="CurrentUser.MemberSince" Source="{x:Static Application.Current}"/>
</MultiBinding>
</ComboBox.IsEnabled>

This is at the 4th point of exercise 1.

indyfromoz
Added by:Thomas Lee

In SpecialFeaturesConverter.cs, update the following two lines of code -

Line 13 - int rating = values[0] is int? (int)values[0] : 0;
Line 14 - DateTime date = values[1] is DateTime ? (DateTime)values[1] : new DateTime(1900, 1, 1);


dmcgloin: You will no longer see the error

Cheers,
indyfromoz

Snippets in a more communicative style
Added by:Thomas Lee

int rating; //declare rating Dim rating

if(values[0] is int)
{
rating = values[0];// no need to do cast because check passes
}
else
{
rating = 0;
}

DateTime date; //Dim DateTime

if(values[1] is DateTime)
{
date = values[1];no need to do cast because check passes
}
else
{
date = new DateTime(1900,1,1);
}

This should be fairly straightforward to convert to VB.NET. Hope that helps.

Invalid Cast exception when Add Product is clicked - VS2008
Added by:MikeT-UK

Class SpecialFeaturesConverter
...
If

values(0) = System.Windows.DependencyProperty.UnsetValue Then
...

Detail message: Operator '=' is not defined for type 'Integer' and type 'NamedObject'
RE: NE1?
Added by:Daniel in CO
Visual basic 2008 adds support for ternary operations via the If() statement. Here is the code for this project:

Dim rating AsInteger = If(TypeOf (values(0)) IsInteger, CType(values(0), Integer), 0)

Dim theDate As DateTime = If(TypeOf (values(1)) Is DateTime, CType(values(1), DateTime), New DateTime(1900, 1, 1))

Lines 8-13 also need to be changed to use the .Equals syntax instead of "="

If values(0).Equals(System.Windows.DependencyProperty.UnsetValue) Then

ReturnFalse

EndIf

If values(1).Equals(System.Windows.DependencyProperty.UnsetValue) Then

ReturnFalse

EndIf

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View