Search code examples
wpfvb.nettouchwindows-10

WPF Control Focus with Touch Screen Monitor and Windows 10


I am developing an application using WPF and VB.net in Visual Studio 2013. This application is to run on a computer with a touch screen monitor.

My development PC is running windows 7, but the computer that will be running this application is using Windows 10. I don't know if this is a specific issue to Windows 10 or a touch interface.

The issue I am having is when using the touch screen monitor, a control is highlighted after you touch the control. I cannot figure out how to automatically remove this highlight. I have tried to change focus and/or set focusable property to false. The only way to stop the control from being highlighted is to touch somewhere else on the screen.

But in Windows 7 using a mouse, I can change focus and with the focusable property set to false; the control does not receive focus at all.

This program is being used without a keyboard(physical or virtual) or mouse. Having a control highlighted is undesirable, in my opinion.

Any advice on how to remove the highlight or prevent it altogether would be greatly appreciated.


Solution

  • All the buttons are highlitghed while the cursor is on them, if you want you can disable the hightlight but it will be disable always. To do so create a custom style and give it to your button, i give you an example:

    <Window.Resources>
        <Style x:Key="CloseButtonStyle" TargetType="Button">
            <Setter Property="OverridesDefaultStyle" Value="True"/>
            <Setter Property="Margin" Value="5"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border Name="border" 
                            BorderThickness="1"
                            Padding="4,2" 
                            BorderBrush="Transparent"
                            Background="{TemplateBinding Background}">
                            <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="border" Property="Background" Value="Red" />
                                <Setter TargetName="border" Property="BorderBrush" Value="Transparent" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    

    this piece of code remove the highlight of your button and change is background to red when you enter it with your cursor. To add it to your button do like this:

    <Button x:Name="CloseButton" Style="{StaticResource CloseButtonStyle}" />
    

    Hope it helps :)