【问题标题】:WPF - Remove mnemonic function from textboxWPF - 从文本框中删除助记符功能
【发布时间】:2016-03-02 23:04:46
【问题描述】:

刚刚发现是什么原因导致 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

谢谢

【问题讨论】:

    标签: wpf vb.net mnemonics


    【解决方案1】:

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

    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
    

    【讨论】:

      猜你喜欢
      • 2014-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多