Event for activating "title" bar in WPF

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I am wondering what event is raised if Window title is activated (i.e. if it
is inactive window title is by default grey and if it is activated it is
blue) in WPF. Activated event does not work :-( and I have tried many other
events and no luck :-(.

Please, help.

Thank you :-).
 
I wouldn't think it has anything to do with the title bar. It is is a
matter of the form being active or having the focus.
 
Hi John,

When a window in a WPF Windows application is activated, the Activated
event of the window is raised. On the contrary, when the window is
deactivated, the Deactivated event of the window is fired.

The following is a sampe of handling the Activated and Deactivated event of
a window.

public partial class Window1 : System.Windows.Window
{
public Window1()
{
InitializeComponent();
this.Activated += new EventHandler(Window1_Activated);
this.Deactivated += new EventHandler(Window1_Deactivated);
}
void Window1_Deactivated(object sender, EventArgs e)
{
Console.WriteLine("deactivated");
}

void Window1_Activated(object sender, EventArgs e)
{
Console.WriteLine("activated");
}
}

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

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://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Linda,

Thank you for reply.
My issue is :
I have background thread which creates and displays "notification" window
(similar windows as Outlook notification of new e mail) every 2 minutes.
If my notification window is displayed it does not have focus. Focus remains
on application which has been active before displaying notification window -
e.g. if you are typing in Word and you receive e-mail - Outlook displays
notification window - but you can continue to type in Word (because
notification window is only displayed but has no input focus, etc.) so Word
does not lost focus - but there is also other window - Outlook notification
window (which is visible but has no focus).

In above case my notification window has IsActive=true but it has no "focus"
because focus is still e.g. in Word application. If I wanted to type into my
notification window, I should need to click it - so title bar of notification
window is changed from "grey" to "blue" - and then it is really focused and
activated and can receive input. But IsFocus is still false no matter window
is focused ... .

So is there any event or something which is raised when title bar changes
color from grye to blue (I am writing still about change of title bar color
because evidently IsFocus is not showing values I should expect) ?

Many thanks.
 
Hi John,

Thank you for your prompt response and detailed explanation.

You have mentioned the notification window is shown but without activated
and focused. How do you do that?

If possible, could you please send me a simple sample project?

To get my actual email address, remove 'online' from my displayed email
address.

Thank you for your cooperation!

Sincerely,
Linda Liu
Microsoft Online Community Support
 
Hi John,

How about the problem now?

If the problem is still not solved, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support
 
Hi Linda :-),

I have sent you mail with my stripped project. (I was out of office ;-) )

Many thanks :-).
 
Hi John,

Thank you for your sample project!

In WPF there are two main concepts that pertain to focus: keyboard focus
and logical focus. Keyboard focus refers to the element that receives
keyboard input and logical focus refers to the element in a focus scope
that has focus.

When a window is shown and activated, it contains the keyboard focus. When
we click the title bar of the window by the mouse, the window will get the
keyboard focus and the GotKeyboardFocus event will be raised.

For more information on focus in WPF, you may refer to the following
document:

http://msdn2.microsoft.com/en-us/library/aa969768.aspx

For your practice, I suggest you listen to the window's GotKeyboardFocus
event to get notified when the user click the title bar of the window.

Please try it out and let me know the result.

Sincerely,
Linda Liu
Microsoft Online Community Support
 
Back
Top