7

I have WPF desktop application with a Button. When I run it on normal PC and go with mouse cursor over the button, it becomes blue (default Windows theme). When I move cursor out, button is gray again. Pretty normal behavior.

But when I run it on Windows 8 tablet, following is happening: I touch the Button, it becomes blue. Then I move up my finger, but button stays blue. There is no MouseLeave event. I see blue button until I click somewhere else on the screen.

Is there any workaround how to prevent this? I know I can remove the whole hover effect, but I don't want to do that unless there is another way.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Stalker
  • 678
  • 1
  • 9
  • 21

3 Answers3

0

check whether following (http://blakenui.codeplex.com/) will help you to handle the issue

WPF: Is there a possibility to "route" ordinary mouse events to touch events in Windows 7

Community
  • 1
  • 1
Chitta
  • 206
  • 2
  • 6
0

I was able to fix that by using following behavior which uses visual states:

public class TouchDeviceMouseOverUIElementFixBehavior : Behavior<UIElement>
{
    protected override void OnAttached()
    {
        AssociatedObject.StylusUp += AssociatedObject_StylusUp;
    }

    protected override void OnDetaching()
    {
        AssociatedObject.StylusUp -= AssociatedObject_StylusUp;
    }

    private void AssociatedObject_StylusUp(object sender, StylusEventArgs e)
    {
        var control = sender as FrameworkElement;
        if (control != null)
        {
            if (!VisualStateManager.GoToElementState(control, "Normal", true))
            {
                VisualStateManager.GoToState(control, "Normal", true);
            }
        }
    }
}
0

You can do this by removing default mouse hover option in WPF. It worked perfectly fine for me.

Here is the source i found the answer

Community
  • 1
  • 1