0

Just discovered what is causing a HTML editor to throw the toys out when using a certain letter on a keyboard...

On the same page there are textboxes that contain things like html page name, title, navigate URL, menu text.... If one of the textboxes contains text with an underscore (say 'Test_Page') then the letter 'P' will not function in the HTML editor. I'm guessing (and could be way off base here as I didn't think textbox.txt could do this unlike Label.content) that WPF is taking the text entry and using it as a mnemonic key.. I do know that setting RecognisesAccessKey to false might cure it, but can't find a way to add that property or access ContentPresenter...

This is the class that I use to create the control and ideally would like to set it here

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

Thank you

gchq
  • 1,603
  • 2
  • 27
  • 52

1 Answers1

0

Couldn't find an easy way to do this from the class, but this works on the page

Dim CP As New ContentPresenter
            CP.RecognizesAccessKey = False

Then add the TextBox to the 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

The add the CP to the grid

  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
gchq
  • 1,603
  • 2
  • 27
  • 52