Yoav
Yoav

Reputation: 3386

Button not losing focus

I have a WPF application running on a Windows 8.1 pro tablet.
When I click on a button in the application the click event gets fired but the button is not losing his focus (it stays in the same color as he was when touched).
If the button is incharge of opening another window and there's a button on the same location in the newly opened window this button also get get "clicked \ focused color".
Also, in some cases (this is inconsistent) the application starts with the button displayed as if it is clicked. This is how I tried to solve it:

    private void btnLogin_GotFocus(object sender, RoutedEventArgs e)
    {
        //remove focus from button
        var scope = FocusManager.GetFocusScope(btnLogin);
        FocusManager.SetFocusedElement(scope, null);
        Keyboard.ClearFocus();
        btnLogin.ReleaseAllTouchCaptures();

        //set focus to another element
        txtName.Focus();
        window_MouseDown(null, null);
    }

    private void window_MouseDown(object sender, MouseButtonEventArgs e)
    {
        window.Focus();
    }

How can I make the button return to it's un-clicked state?

Upvotes: 0

Views: 213

Answers (2)

Dhaval Joshi
Dhaval Joshi

Reputation: 54

use Buttons Click event Instead of Mouse Down Event

Upvotes: 0

6a6179
6a6179

Reputation: 280

I'm not sure of the exact syntax, however something along the lines of setting an isFocused property to false in the window_MouseDown procedure may be a starting point to the solution....

I hope this has helped to some extent, if not, apologies and good luck.

Upvotes: 1

Related Questions