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

  • Home
  • SEARCH
  • 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 645937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:33:26+00:00 2026-05-13T21:33:26+00:00

While designing a new WPF application I noticed exceptions not being thrown during data

  • 0

While designing a new WPF application I noticed exceptions not being thrown during data binding for controls with DataTemplates. To test I wrote the following simple user control with as little logic as possible. I’m using .NET 3.5 SP1, VS2008 SP1 running on WIN7.

When the DataContext is set, TestMethod is called and an exception is thrown in the codebehind but the application doesn’t break.

Would someone mind explaining what is happening when the DataTemplate is being created? Specifically I’m interested in where the exception goes.

Below is the XAML code:

<UserControl x:Class="WPF2008.DataTemplateQuestion"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Height="300" Width="300">
    <UserControl.Resources>
        <DataTemplate x:Key="TESTKey">
            <Border BorderBrush="Black" BorderThickness="10">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition></RowDefinition>
                        <RowDefinition></RowDefinition>
                        <RowDefinition></RowDefinition>
                        <RowDefinition></RowDefinition>
                    </Grid.RowDefinitions>
                    <TextBox Grid.Row="0" Text="{Binding Path=Txt}" />
                    <TextBox Grid.Row="1" Text="{Binding Path=Lbl}" />
                    <TextBox Grid.Row="2" Text="Am I disabled?" />
                    <TextBox Grid.Row="3" Text="I am disabled." IsEnabled="False" />
                </Grid>
            </Border>
        </DataTemplate>
    </UserControl.Resources>
    <Grid>
        <Label x:Name="lblTest" Content="{Binding Path=TestMethod}" ContentTemplate="{StaticResource TESTKey}" />
    </Grid>
</UserControl>

Below is the codebehind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WPF2008
{
    public partial class DataTemplateQuestion : UserControl
    {
        public DataTemplateQuestion()
        {
            try
            {
                InitializeComponent();
                lblTest.DataContext = new TestClass();
            }
            catch (Exception e)
            {
                // ADDING A BREAKPOINT HERE DOESN'T CATCH THE EXCEPTION
                throw e; 
            }
        }
    }

    public class TestClass
    {
        public TestValue TestMethod
        {
            get
            {
                // BREAKPOINT WILL BE HIT WHEN DEBUGGING BUT THE EXCEPTION DISAPPEARS
                throw new Exception("WATCH ME DISAPPEAR");
                return new TestValue { Lbl = "Label", Txt = "Text" };
            }
        }

        public class TestValue
        {
            public string Lbl { get; set; }
            public string Txt { get; set; }
        }
    }
}
  • 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-13T21:33:27+00:00Added an answer on May 13, 2026 at 9:33 pm

    Exceptions thrown by data bindings get translated into trace, which are delivered to the DataBindingSource TraceSource, which has a source name of “System.Windows.Data”.

    You can convert these into exceptions by creating a subclass of TraceListner that throws an exception on a trace, and add it to the Listeners collection of the TraceSourceSource. This can be done either in code or in your App.config file.

    Here is how you would do it in code:

    System.Diagnostics.PresentationTraceSources.DataBindingSource.Listeners.Add(
      new MyTraceListener());
    

    See TraceSource and TraceListener documentation and samples for more details.

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

Sidebar

Ask A Question

Stats

  • Questions 317k
  • Answers 317k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Should work. But seems that your app is missing a… May 13, 2026 at 11:39 pm
  • Editorial Team
    Editorial Team added an answer Because inheritance is intended to modify behaviour. Behaviour is exposed… May 13, 2026 at 11:39 pm
  • Editorial Team
    Editorial Team added an answer There are no regular expressions in XPath 1.0, and there… May 13, 2026 at 11:39 pm

Related Questions

I'm designing a system for a new business and am in a unique carte
I am designing a new laboratory database. I want all the raw results (for
I'm designing a new system and finding that I am struggling with the structure
I have to make a new report using crystal report8.5 . I have created
Here at SO there's a lot of focus on designing web applications but I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.