473,385 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 RoutedEventHandler(ucRole_LUProps_GotFocus);

this.LostFocus += new RoutedEventHandler(ucRole_LUProps_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?

Thanks.
Oct 21 '08 #1
1 13793
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.IsFocused property.
So when click the UserControl itself by mouse, the GotFocus event won't
fire. However, you can handle the UserControl.MouseDown event, and call
the Focus() method to force the UserControl to get focused, for example:

void UserControl1_MouseDown(object sender, MouseButtonEventArgs e)
{
this.Focus();
}

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.

Sincerely,
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****@microsoft.com.

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

http://msdn.microsoft.com/en-us/subs...#notifications.

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
http://support.microsoft.com/select/default.aspx?

target=assistance&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

6
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...
2
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...
4
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
4
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...
1
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
0
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...
1
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....
3
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
26
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

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.