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

Posted on 2014-08-25
Medium Priority
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 84

Expert Comment

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

Accepted Solution

Jaime Olivares earned 2000 total points
ID: 40284566
The LostFocus event should bubble up, so you just need to implement an event handler in your page.

Tutorial: http://www.codeproject.com/Articles/464926/To-bubble-or-tunnel-basic-WPF-events

Author Comment

ID: 40285522
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Loops Section Overview
Suggested Courses
Course of the Month15 days, 23 hours left to enroll

850 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