473,705 Members | 2,522 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need good way to handle a wpf UC GotFocus and LostFocus events

I have a c# 3.5 wpf app which uses user controls for data entry screens.
These data entry screens can be nested inside of each. We can also have
several ones open side by side at the same time. All are in a single
window. My challenge is to know when a data entry screen (UC) becomes the
active control, and when the active user control looses focus and when the
next one gets the focus, and so on. When a user control gets or looses
focus, I want to configure buttons in the window's toolbar according to the
user control that currently has the focus and its current state. In the
winforms days, I could use the user control's Enter and Leave events which
worked very well. In this case I tried to use the user control's GotFocus
and LostFocus events which doesn't work very well at all

this.Focusable = true;

this.GotFocus += new RoutedEventHand ler(ucRole_LUPr ops_GotFocus);

this.LostFocus += new RoutedEventHand ler(ucRole_LUPr ops_LostFocus);

The GotFocus event only fires when I click in a control such as a textbox or
combobox in the user control. It doesn't fire when I mouse click on the
user control it's self or when I tab into it. Furthermore, The Lostfocus
event never fires.

Can anyone recommend a good solution to the problem?

Oct 21 '08 #1
1 13863
Hi moondaddy,

As I understand, you create an UserControl in WPF, and put some controls on
the UserControl, you want to know when the UserControl get focused, and
when it lost focus.

When click the UserControl itself by mouse, the UserControl does not get
focused, you can check this my checking the UserControl.IsF ocused property.
So when click the UserControl itself by mouse, the GotFocus event won't
fire. However, you can handle the UserControl.Mou seDown event, and call
the Focus() method to force the UserControl to get focused, for example:

void UserControl1_Mo useDown(object sender, MouseButtonEven tArgs e)

From you description, when you tab into the UserControl, the GotFocus event
does not fire, and the LostFocus event never fire as well. From my
experience, these events should fire properly, anyway, I can help you to
find out the problem if you send me a sample code to reproduce this
problem. My email is v-****@microsoft. com.

I look forward to hearing from you.

Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can

improve the support we provide to you. Please feel free to let my manager
know what you think of the level

of service provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

=============== =============== =============== =====
Get notification to my posts through email? Please refer to


Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from

the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take

approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The

offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis

issues. Issues of this nature are best handled working with a dedicated
Microsoft Support Engineer by

contacting Microsoft Customer Support Services (CSS) at

target=assistan ce&ln=en-us.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 22 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: R.Wieser | last post by:
Hello All, I'm trying to get a "Virtual Listbox" to work. I've currently got a form, and used CreateWindowExA to create a ListBox with the LBS_OWNERDRAWFIXED and LBS_NODATA flags on it. I've allso subclassed the window and do see all kinds of WS_??? messages coming by. But now I'm stuck :-\ I've got *no* idea what to do next, and all my searching on the web leads me
by: Chris LaJoie | last post by:
My app needs to use the LostFocus event on several different controls on a form. Unfortunately, I got done coding it only to find out that none of them ever fire. They are assigned to, and I'm sure I'm doing everything right, but they're not working. Anyone else have this problem/know how to fix it? Chris LaJoie
by: Sezhman | last post by:
Hi, I developed an ASP.NET application. I am testing my application with all possibility of data. How to handle HTTP errors (Codes) in ASP.NET. Regards, Sezhman
by: dudzcom | last post by:
hi, this is the first time i've posted to this board, though i have been a devoted lurker for some time i have been working in vb.net and run into a couple problems that seem to require solutions involving what was in previous versions of vb, refered to as gotfocus/lostfocus events. however, it seems that though people online refer to them, my vb.net does not have them just to show i've not lost my mind...
by: Dzemo | last post by:
Like I said I need good PDF to catch up to VS2005 I'm good in VS2003 so any good pages or sources or anything. Thx
by: **Developer** | last post by:
Anyone know a good reference for when Events occur? I'm thinking of Load, HandleCreated, Enter, Resize(first time), Print(first time),... and I don't know what else might be run on control (or Form) startup Thanks
by: sravan_reddy001 | last post by:
do we hav any methods defined in C# to handle all the mouse events like ->mouseover ->mousemoved ->mousedragged i just want to create a drawing box....
by: premkutuva | last post by:
Hi I created a dynamic textbox on a button click event, i like to handle a lostfocus event for the textbox, how can i done this
by: JFKJr | last post by:
Hello everyone, I have added a ComboBox in excel spreadsheet using the following Access VBA code. Public eXL As New eventsXL Function Create_ComboBox() With eXL If .XL Is Nothing Then Set .XL = New Excel.Application .XL.Visible = True
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.