Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6184621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:34:06+00:00 2026-05-24T01:34:06+00:00

I’m trying to implement binding validation using Silverlight on Windows Phone, but all I

  • 0

I’m trying to implement binding validation using Silverlight on Windows Phone, but all I get is the debugger breaking on an unhandled exception instead, and the validation not happening.

I’m following the recommendations from an MSDN article on Data Binding.

Here is what I have tried to do to set it up:

Debug -> Exceptions -> Common Language Runtime Exceptions – User-unhandled is unchecked

On the data template for the ListBoxItem, I declare two-way binding with validations:

<TextBox x:Name="LastReadingValue" Text="{Binding LastReadingValue, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}" />

In the setter I raise an exception if the TextBox data is incorrect:

public string LastReadingValue
        {
            get
            {
                return _lastReadingValue;
            }
            set
            {
                try
                {
                    double reading = System.Convert.ToDouble(value);
                    _lastReadingValue = String.Format("{0:0.00}", reading);
                }
                catch (FormatException fe)
                {
                    throw new Exception("The meter reading must be a number like 7561.41");
                }
                NotifyOfPropertyChanged("LastReadingValue");
            }
        }

On the ListBox I declare the handler for the BindingValidationError event:

<ListBox x:Name="NewMeterReadingsListBox" ItemsSource="{Binding Meters}" ItemTemplate="{StaticResource NewMeterReadingDataTemplate}" BindingValidationError="ListBox_BindingValidationError"/>

The handler for the BindingValidationError never gets called:

private void ListBox_BindingValidationError(object sender, ValidationErrorEventArgs e)
        {
            Debug.WriteLine("BindingValidationError");
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:34:07+00:00Added an answer on May 24, 2026 at 1:34 am

    Ok – 2nd try at an answer.

    A couple of interesting things happened when I tried this myself. I started from the WindowsPhoneDataboundApplication then added a TextBox and validation to the app’s ListBox. I’m using the WP Mango Beta 2 tools (not the Beta 2 update from yesterday).

    1. When debugging: if an invalid value is entered I get a debug break and prompt from VS on the throw line says that the exception is unhandled. HOWEVER: the BindingValidationError handler is called fine, the application keeps running and Application.UnhandledException isn’t called.
    2. In the _BindingValidationError function the Debug.WriteLine text is often difficult to spot with the other exception text in the output window. If you make it more obvious by forcing a new line you should spot the text:

      Debug.WriteLine("\n\n*** BindingValidationError ***\n");

    So basically it’s working for me, but there are a couple of things to watch out for when debugging.

    If you’re targetting WP Mango I’d recommend you consider the Silverlight 4 way of doing data validation which doesn’t involve throwing and catching exceptions – I agree with Claus insofar as using exceptions is a really ugly way of doing validation. The SL4 alternative involves implementing the IDataErrorInfo and INotifyDataErrorInfo interfaces in your bound class. I haven’t tried this approach personally myself though.

    Edit:

    If you really want to turn off the break on exceptions you can do it from the VS2010 “Debug” menu, “Exceptions” item. Then de-select the exception type you don’t want VS to do break on if it is unhandled.

    If you create your own custom Exception class just for binding validation and disable the debug break only for that Exception type, then you will be able to have normal VS behaviour for your app’s exceptions except when when dealing with binding failures.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.