Silverlight text box cancels

I am trying to get the keydown keybox event to catch the backspace key down event. This works for me by adding a class that overrides the text box. What I do not know how to do is to contact the class where the text field is in the user control.

When the user enters a text field ... say abcd or backspace, I need to update something in usercontrol. let me say that I want to have something that displays the number of characters in the text box. can someone help me. That's what i still have

Option Strict On
Imports System.Text.RegularExpressions

Partial Public Class Page
    Inherits UserControl

    Public Sub New()
        InitializeComponent()
        Dim textbox As New MyTextBox() With {.Width = 300, .Height = 100}
        LayoutRoot.Children.Add(textbox)
    End Sub
End Class

Public Class MyTextBox
    Inherits TextBox
    Protected Overrides Sub OnKeyDown(ByVal e As KeyEventArgs)
        MyBase.OnKeyDown(e)
        If e.Key = Key.Back Then
            e.Handled = True
            MyBase.OnKeyDown(e)

        ElseIf e.Key = Key.Delete Then
            e.Handled = True
            MyBase.OnKeyDown(e)
        End If
    End Sub
End Class

thanks shannon

+3
source share
2 answers

TextBox. TextBox.TextChanged UserControl. , TextBox. , .

. :

Partial Public Class Page
    Inherits UserControl

    Private TextBox1 as TextBox

    Public Sub New()
        InitializeComponent()
        TextBox1 = New TextBox() With {.Width = 300, .Height = 100}
        LayoutRoot.Children.Add(textbox)
    End Sub

    Private Sub OnTextChanged(sender as Object, e as TextChangedEventArgs) Handles TextBox1.TextChanged
        If e.Key = Key.Back Then
            e.Handled = True
        ElseIf e.Key = Key.Delete Then
            e.Handled = True
        End If
    End Sub
End Class

( VB , .)

- TextBox UserControl. , UserControl .

+2

, . Silverlight, . , , , . xaml:

    <TextBox x:Name="txtInput" />
    <TextBlock Text="{Binding ElementName=txtInput, Path=Text.Length}" />
0

Source: https://habr.com/ru/post/1708907/


All Articles