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 7624319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:55:54+00:00 2026-05-31T04:55:54+00:00

What method do you use when debugging WPF events or bindings? I tried to

  • 0

What method do you use when debugging WPF events or bindings?

I tried to use breakpoint, but it seems like that something’s wrong with my XAML or behind the code that it never hits the breakpoint.

Is there a way to see when I click something in WPF, what event messages are popping up or not popping up to understand what went wrong?

  • 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-31T04:55:55+00:00Added an answer on May 31, 2026 at 4:55 am

    In last 3 years of building WPF applications almost full-time I have collected a variety of reactive and preventative solutions to ensure that everything binds together properly.

    Note: I will give you a quick summary now and then post back in the morning (in 10 hours time) with code samples / screenshots.

    These are my most effective tools:

    1) Create a converter that breaks the debugger when the Convert and ConvertBack is executed. A quick and useful way to ensure that you have the values that you expect. I first learnt of this trick from Bea Stollnitz’s blog post.

    DebugConverter.cs

    public class DebugConverter : IValueConverter
    {
    
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (Debugger.IsAttached)
                Debugger.Break();
    
            return Binding.DoNothing;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (Debugger.IsAttached)
                Debugger.Break();
    
            return Binding.DoNothing;
        }
    
    }
    

    2) Create a TraceListener that intercepts any errors. This is similar to what you see in the Visual Studio Output Window when you have a debugger attached. Using this method I can get the debugger to break when there is a exception thrown during a binding operation. This is better than setting PresentationTraceSources.TraceLevel as it applies to the entire application, not per-binding.

    DataBindingErrorLogger.cs

    public class DataBindingErrorLogger : DefaultTraceListener, IDisposable
    {
        private ILogger Logger;
    
        public DataBindingErrorLogger(ILogger logger, SourceLevels level)
        {
            Logger = logger;
    
            PresentationTraceSources.Refresh();
            PresentationTraceSources.DataBindingSource.Listeners.Add(this);
            PresentationTraceSources.DataBindingSource.Switch.Level = level;
        }
    
        public override void Write(string message)
        {
        }
    
        public override void WriteLine(string message)
        {
            Logger.BindingError(message);
    
            if (Debugger.IsAttached && message.Contains("Exception"))
                Debugger.Break();
        }
    
        protected override void Dispose(bool disposing)
        {
            Flush();
            Close();
    
            PresentationTraceSources.DataBindingSource.Listeners.Remove(this);
        }
    
    }
    

    Usage

    DataBindingErrorLogger = new DataBindingErrorLogger(Logger, SourceLevels.Warning);
    

    In the above, ILogger is an NLog log writer. I have a more complex version of DefaultTraceListener that can report a full stack trace and actually throw exceptions however this will be enough to get you started (Jason Bock has an article on this extended implementation if you want to implement it yourself, although you will need code to actually to get it work).

    3) Use the Snoop WPF introspection tool to delve into your view and inspect your data objects. Using Snoop you can view the logical structure of your view and interactively change values to test different conditions.

    Snoop WPF

    Snoop WPF is absolutely essential to the iteration time of any WPF application. Among its many features, the Delve command allows you to drill down to your view/view model and interactively tweak values. To delve into a property, right-click to open the context menu and select Delve command; to go back up a level (un-delve?) there is a small button ^ in the top-right corner. For example, try delving into the DataContext property.

    Edit: I can’t believe I just noticed this, however there is a Data Context tab in the Snoop WPF window.

    DataContext Tab

    4) Runtime checks on INotifyPropertyChanged events in #DEBUG. As the Data Binding system relies on being notified when properties have changed, it is important for your sanity that you are notifying that the correct property has changed. With a bit of reflection magic you can Debug.Assert when something is wrong.

    PropertyChangedHelper.cs

    public static class PropertyChangedHelper
    {
        #if DEBUG
        public static Dictionary<Type, Dictionary<string, bool>> PropertyCache = new Dictionary<Type, Dictionary<string, bool>>();
        #endif
    
        [DebuggerStepThrough]
        public static void Notify(this INotifyPropertyChanged sender, PropertyChangedEventHandler eventHandler, string propertyName)
        {
            sender.Notify(eventHandler, new PropertyChangedEventArgs(propertyName), true);
        }
    
        [DebuggerStepThrough]
        public static void Notify(this INotifyPropertyChanged sender, PropertyChangedEventHandler eventHandler, string propertyName, bool validatePropertyName)
        {
            sender.Notify(eventHandler, new PropertyChangedEventArgs(propertyName), validatePropertyName);
        }
    
        [DebuggerStepThrough]
        public static void Notify(this INotifyPropertyChanged sender, PropertyChangedEventHandler eventHandler, PropertyChangedEventArgs eventArgs)
        {
            sender.Notify(eventHandler, eventArgs, true);
        }
    
        [DebuggerStepThrough]
        public static void Notify(this INotifyPropertyChanged sender, PropertyChangedEventHandler eventHandler, PropertyChangedEventArgs eventArgs, bool validatePropertyName)
        {
            #if DEBUG
            if (validatePropertyName)
                Debug.Assert(PropertyExists(sender as object, eventArgs.PropertyName), String.Format("Property: {0} does not exist on type: {1}", eventArgs.PropertyName, sender.GetType().ToString()));
            #endif
    
            // as the event handlers is a parameter is actually somewhat "thread safe"
            // http://blogs.msdn.com/b/ericlippert/archive/2009/04/29/events-and-races.aspx
            if (eventHandler != null)
                eventHandler(sender, eventArgs);
        }
    
        #if DEBUG
        [DebuggerStepThrough]
        public static bool PropertyExists(object sender, string propertyName)
        {
            // we do not check validity of dynamic classes. it is possible, however since they're dynamic we couldn't cache them anyway.
            if (sender is ICustomTypeDescriptor)
                return true;
    
            var senderType = sender.GetType();     
            if (!PropertyCache.ContainsKey(senderType))
                PropertyCache.Add(senderType, new Dictionary<string,bool>());
    
            lock (PropertyCache)
            {
                if (!(PropertyCache[senderType].ContainsKey(propertyName)))
                {
                    var hasPropertyByName = (senderType.GetProperty(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static) != null);
                    PropertyCache[senderType].Add(propertyName, hasPropertyByName);
                }
            }
    
            return PropertyCache[senderType][propertyName];
        }
        #endif
    
    }
    

    HTH,

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

Sidebar

Related Questions

I need to use method like: DoSomething<(T)>(); But i don't know which Type i
I'm trying to use opera dragonfly for debugging, it seems quite nice, but I'm
When I'm debugging, I often have to deal with methods that does not use
What is the method to use to rotate an image about a point that
In the first method listed below, the use method, it looks to me like
How do I write a unit test for a method that use an external
I'm debugging a Delphi code that use TJvProgramVersionCheck component from the excellent JVCL libs.
I have a WPF click-once application that makes use of an unmanaged dll. When
I'm currently debugging a method we use to tag images with a certain text
The main documentation describe it at debugging callbacks but it seems to not exists:

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.