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

Related Questions

While designing a new feature for a software application that I'm working on, I
I'm designing some new class diagrams for extending an existing office automation application. In
I'm currently about to start designing a new application. The application will allow a
This question came up while designing a dedicated ACL system for a custom application,
There are two methods which I noticed while designing child tables Method 1 Example:
while designing my user control, i encountered the following problem: i would like to
Is including a application package prefix while defining a custom action string is convention
While debugging and keep pressing F5, if the source code does not exist, eclipse
While developing an application using gwt in ecliplse crashed. Now the server is running
while looking at some code I stumbled onto: throw /*-->*/new std::exception (//... and I

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.