WPF Window.Activate() Returns False
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: WPF Window.Activate() Returns False

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Posts
    3

    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, which works fine most of the time, but sometimes it fails, and returns false. In particular, it seems to always fail on virtual machines. In cases where it fails, the application doesn't have focus (even if we set up our Login form to be top most) but the button in the task bar flashes.

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

  2. #2
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: WPF Window.Activate() Returns False

    Why not to open it as modal dialog? It could be safer.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  3. #3
    Join Date
    Oct 2009
    Posts
    3

    Re: WPF Window.Activate() Returns False

    The dialog IS modal (we use ShowDialog() ), so maybe also setting it top most was a bit overkill, but since we were having focus issues, we threw everything we could think of at it. I believe NOT making it top most doesn't fix the issue anyway.

  4. #4
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: WPF Window.Activate() Returns False

    Do you use just ONE gui thread (the one in which message loop runs), or more (e.g. for splashscreen)?
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  5. #5
    Join Date
    Oct 2009
    Posts
    3

    Re: WPF Window.Activate() Returns False

    The login window itself is shown in a separate STA thread.

  6. #6
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: WPF Window.Activate() Returns False

    I think this could be the case. There are problems with focus if there are more than one thread where message loop is running.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center