Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 Data Binding Demo

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
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

  • 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.

  • 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.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Sample doesn't build in VS2008.      Daniel McGloin   |   Edit   |   Show History
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      Juan Carlos Ruiz [BogotaDotNet.org] ... Thomas Lee   |   Edit   |   Show History
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      Indrajit Chakrabarty ... Thomas Lee   |   Edit   |   Show History

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

N E 1?      BellerophonUK ... Thomas Lee   |   Edit   |   Show History
NE1 know how to code this in vb: -

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

Such a shame MS are not consistent and provide code in both vb and c# for all their examples, it's proving very diffucult to follw when they mix and match so much omitting vb half way through an example



[tfl - 22 02 09] You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the

MSDN Newsgroups at http://www.microsoft.com/communities/newsgroups/en-us/.d You are much more likely get a quick

response using the forums than through the Community Content.
For specific help about:
Visual Studio : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C&
.NET Framework : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
All Public : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C&

Snippets in a more communicative style      Mai Kalange ... Thomas Lee   |   Edit   |   Show History

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      MikeT-UK   |   Edit   |   Show History

Class SpecialFeaturesConverter
...
If

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

Detail message: Operator '=' is not defined for type 'Integer' and type 'NamedObject'
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker