.NET Framework Bookmark and Share   
 index > Windows Presentation Foundation (WPF) > WPF Window.Activate() Returns False
 

WPF Window.Activate() Returns False

Hi all,

We've got an application that, when started, displays a login window. We'd like the window to be the active window, and the focus to be on the username textbox. We call the Activate() method in our overridden OnContentRendered method, and this works fine on real, physical machines, but for some reason, on VMWare, it doesn't work. It doesn't seem to work through VMRC either. The Activate() method, when called, actually returns false to indicate that it failed.

Does anyone know what might cause the Activate() method to return false ?
Ssebu
Hi Ssebu,

I try with the following code but cannot reproduce the problem, the Activate method returns true either on local physical machine or VMWare. Could you show us the code you used?

public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}

void Window1_Loaded(object sender, RoutedEventArgs e)
{

Window2 w = new Window2();
w.Show();

}
}


public partial class Window2 : Window
{
public Window2()
{
InitializeComponent();
}

protected override void OnContentRendered(EventArgs e)
{
bool b = this.Activate();

MessageBox.Show(b.ToString());

base.OnContentRendered(e);
}
}


Best Regards,
Zhi-Xin


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework!
Zhi-Xin Ye
Hi Ssebu,

Could you provide the sample project to reproduce the problem?
Tony.Tam
I tried Zhi-Xin Ye's sample, and indeed it doesn't reproduce the problem. In our case the application is very big and complex, so there's probably something in our code that causes the behavior. I'll try to find exactly what it is that does that, but for now no, I don't have a better sample. Sorry.
Ssebu

You can use google to search for other answers

Custom Search

More Threads

• Problems zooming a canvas
• DrawingContext.DrawEllipse(...) in .Net Micro Framework
• Assign CTRL+P As a Shortcut Key
• Always on top, even in fullscreen-games.
• Polyline Points property updates
• Referencing names XAML controls in code-behind problem.
• MouseOver Triggers and accessing them programmatically.
• ListView scroolbar problem
• Hyperlinks in WPF RichTextBox
• Smooth scrolling images