How do I capture/intercept the "LostFocus" event on every control on a WPF/XAML page?

Posted on 2014-08-25
Last Modified: 2014-08-27
I want to capture/intercept the lostfocus event on every textbox, listbox and checkbox on my WPF/XAML page.  I am needing execute another piece of code whenever one of these events happens.  How can I do that without adding a "LostFocus" element to each UIElement?
Question by:Bruce
    LVL 77

    Expert Comment

    by:David Johnson, CD, MVP
    how will you know which control has lost focus without adding the appropriate lost focus to each control?
    LVL 55

    Accepted Solution

    The LostFocus event should bubble up, so you just need to implement an event handler in your page.

    LVL 1

    Author Comment

    David, I understand why you ask but I don't need to know the control for what I am trying to do.  I just need to know that an editable control has lost focus.   What I am doing in the event handler is comparing two objects.  One holds the original values collected from the database and the other is the object bound via property to all the controls.  I have one link statement the compares the properties of theses objects and returns me a list of the "changes".  

    This technique means I don't have to have an "OnPropertyChanged" call inside each of my properties in my POCO objects.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now