0

刚刚发现是什么导致 HTML 编辑器在键盘上使用某个字母时抛出玩具......

在同一页面上,有一些文本框包含诸如 html 页面名称、标题、导航 URL、菜单文本等内容。如果其中一个文本框包含带下划线的文本(例如“Test_Page”),则字母“P”不会HTML 编辑器中的函数。我在猜测(并且可能在这里偏离基础,因为我认为 textbox.txt 不像 Label.content 那样可以做到这一点)WPF 正在获取文本输入并将其用作助记键。我确实知道该设置RecognisesAccessKey 为 false 可能会治愈它,但找不到添加该属性或访问 ContentPresenter 的方法...

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

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

谢谢

4

1 回答 1

0

在课堂上找不到简单的方法来做到这一点,但这在页面上有效

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
于 2016-03-03T02:18:54.273 回答