我不想在Button边缘看到虚线

时间:2018-12-25 05:53:04

标签: c# wpf vb.net xaml

1-创建vb.net / wpf应用程序。

2-创建三个WPF Windows,分别为 Window1 Window2 Window3

3-将以下xaml代码复制并粘贴到 MainWindow 中。

<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
    <StackPanel Width="180" Height="120">
        <Button x:Name="Button1" Height="30" Margin="5" Content="Button1"/>
        <Button x:Name="Button2" Height="30" Margin="5" Content="Button2"/>
        <Button x:Name="Button3" Height="30" Margin="5" Content="Button3"/>
    </StackPanel>
</Grid>
</Window>

4-将以下vb.net代码复制并粘贴到后面的 MainWindow 代码中。

Class MainWindow

Private Sub Button1_Click(sender As Object, e As RoutedEventArgs) Handles Button1.Click
    Dim myWindow1 As New Window1()
    myWindow1.Show()
End Sub

Private Sub Button2_Click(sender As Object, e As RoutedEventArgs) Handles Button2.Click
    Dim myWindow2 As New Window2()
    myWindow2.Show()
End Sub

Private Sub Button3_Click(sender As Object, e As RoutedEventArgs) Handles Button3.Click
    Dim myWindow3 As New Window3()
    myWindow3.Show()
End Sub

Private Sub MainWindow_KeyDown(sender As System.Object, e As System.Windows.Input.KeyEventArgs) Handles MyBase.KeyDown
    If e.Key = Key.F1 Then
        Dim myWindow1 As New Window1()
        myWindow1.Show()
    End If

    If e.Key = Key.F2 Then
        Dim myWindow2 As New Window2()
        myWindow2.Show()
    End If

    If e.Key = Key.F3 Then
        Dim myWindow3 As New Window3()
        myWindow3.Show()
    End If
End Sub

End Class

5-运行此项目,然后单击 Button2 ,然后关闭 Window2 ,然后按 F3 ,然后关闭 Window3

我的问题:

我不想在Button边缘看到虚线,就像您在这里看到的https://prnt.sc/lz8856

1 个答案:

答案 0 :(得分:3)

此虚线是您的焦点。有多种方法可以消除它。

  1. 在XAML中为您的按钮设置IsTabStop="False",当您在按钮上[Tab]时将跳过该按钮,但是在单击鼠标后将保持用户焦点。因此,例如,在鼠标单击后,您可以通过[Space bar]按下此按钮。

  2. 在XAML中为您的按钮设置Focusable="False",然后当您[Tab]跳过按钮时将被跳过,并在鼠标单击后保持用户焦点。

  3. 在XAML中为您的按钮设置FocusVisualStyle="{x:Null}",然后只需删除此行,您的标签顺序和焦点保持将保持不变。