WPF - 从文本框中删除助记符功能

WPF - Remove mnemonic function from textbox

刚刚发现是什么导致 HTML 编辑在键盘上使用特定字母时将玩具扔掉...

同一页面上的文本框包含 html 页面名称、标题、导航 URL、菜单文本...。如果其中一个文本框包含带下划线的文本 (说 'Test_Page') 那么字母 'P' 将不会在 HTML 编辑器中起作用。我猜测(并且可能偏离这里的基础,因为我不认为 textbox.txt 可以像 Label.content 那样做到这一点)WPF 正在获取文本条目并将其用作助记键..我确实知道将 RecognisesAccessKey 设置为 false 可能会解决它,但找不到添加 属性 或访问 ContentPresenter...

的方法

这是我用来创建控件的 class,理想情况下我想在此处设置它

Public Class TBx
Inherits TextBox
Public Shared IsNewRecordProperty As DependencyProperty = DependencyProperty.Register("IsNewRecord", GetType(Boolean), GetType(TBx), New PropertyMetadata(New PropertyChangedCallback(AddressOf IsNewRecordChanged)))
Public Property IsNewRecord As Boolean
    Get
        Return GetValue(IsNewRecordProperty)
    End Get
    Set(value As Boolean)
        SetValue(IsNewRecordProperty, value)
    End Set
End Property

Protected Overrides Sub OnInitialized(e As System.EventArgs)
    MyBase.OnInitialized(e)
    VerticalAlignment = Windows.VerticalAlignment.Center
    HorizontalAlignment = Windows.HorizontalAlignment.Left
    BorderBrush = New SolidColorBrush(Colors.Silver)
    Height = 22
    SpellCheck.IsEnabled = True
    UndoLimit = 0

    If IsNewRecord = True Then
        BorderThickness = New Thickness(1)
        IsReadOnly = False
        Background = New SolidColorBrush(Colors.White)
    Else
        BorderThickness = New Thickness(0)
        IsReadOnly = True
        Background = New SolidColorBrush(Colors.Transparent)
    End If

End Sub

Private Shared Sub IsNewRecordChanged(sender As DependencyObject, e As DependencyPropertyChangedEventArgs)
    Dim vControl As TBx = TryCast(sender, TBx)
    Dim vBoolean As Boolean = e.NewValue
    If vBoolean = True Then
        vControl.BorderThickness = New Thickness(1)
        vControl.IsReadOnly = False
        vControl.Background = New SolidColorBrush(Colors.White)
    Else
        vControl.BorderThickness = New Thickness(0)
        vControl.IsReadOnly = True
        vControl.Background = New SolidColorBrush(Colors.Transparent)
    End If
End Sub
End Class

谢谢

无法从 class 找到执行此操作的简单方法,但这在页面上有效

Dim CP As New ContentPresenter
            CP.RecognizesAccessKey = False

然后将 TextBox 添加到 ContentPresenter

Case 1
                    vLabel.Text = "Page Name"

                    With vTB
                        .Width = 200
                        .Name = vName & "PageNameTB"
                        .ToolTip = "This is the short name for the page"
                        .IsNewRecord = IsNewRecord
                    End With
                    CP.Content = vTB

将CP加入网格

  RegisterControl(SecurePage_Grid, vTB)

            Grid.SetColumn(vLabel, 0)
            Grid.SetRow(vLabel, i)

            If i = 1 Then
                Grid.SetRow(CP, i)
                Grid.SetColumn(CP, 1)
            Else
                Grid.SetRow(vTB, i)
                Grid.SetColumn(vTB, 1)
            End If

            vGrid.Children.Add(vLabel)
            If i = 1 Then
                vGrid.Children.Add(CP)
            Else
                vGrid.Children.Add(vTB)
            End If