Files
EgtWPFLib5/EgtTextBox.xaml.vb
2025-03-21 23:42:17 +01:00

693 lines
34 KiB
VB.net

Imports System.Windows.Threading
Public Class EgtTextBox
Sub New()
InitializeComponent()
End Sub
Public Shared ReadOnly TextProperty As DependencyProperty =
DependencyProperty.Register("Text", GetType(String), GetType(EgtTextBox), New FrameworkPropertyMetadata(String.Empty, New PropertyChangedCallback(AddressOf Text_PropertyChanged)) With {.BindsTwoWayByDefault = True})
Public Property Text As String
Get
Return CStr(GetValue(TextProperty))
End Get
Set(value As String)
SetValue(TextProperty, value)
End Set
End Property
' Delegato ed Evento creati per gestire il TextChanged nel code-behind di LicenseManager
Public Delegate Sub EgtTextBoxTextChanged(ByVal sender As Object, ByVal e As TextChangedEventArgs)
Public Event TextChanged As EgtTextBoxTextChanged
Protected Sub EgtTextBox_TextChanged_LM(sender As Object, e As TextChangedEventArgs) Handles TxBx.TextChanged
RaiseEvent TextChanged(sender, e)
End Sub
Public ReadOnly Property LineCount As Integer
Get
Return TxBx.LineCount
End Get
End Property
Public Shared ReadOnly IsReadOnlyProperty As DependencyProperty =
DependencyProperty.Register("IsReadOnly", GetType(Boolean), GetType(EgtTextBox), New FrameworkPropertyMetadata(New PropertyChangedCallback(AddressOf IsReadOnly_PropertyChanged)) With {.BindsTwoWayByDefault = True})
Public Property IsReadOnly As Boolean
Get
Return CBool(GetValue(IsReadOnlyProperty))
End Get
Set(value As Boolean)
SetValue(IsReadOnlyProperty, value)
End Set
End Property
Public Shared Shadows ReadOnly VerticalContentAlignmentProperty As DependencyProperty =
DependencyProperty.Register("VerticalContentAlignment", GetType(VerticalAlignment), GetType(EgtTextBox), New FrameworkPropertyMetadata(New PropertyChangedCallback(AddressOf VerticalAlignment_PropertyChanged)) With {.BindsTwoWayByDefault = True})
Public Overloads Property VerticalContentAlignment As VerticalAlignment
Get
Return CType(GetValue(VerticalContentAlignmentProperty), VerticalAlignment)
End Get
Set(value As VerticalAlignment)
SetValue(VerticalContentAlignmentProperty, value)
End Set
End Property
Public Shared Shadows ReadOnly HorizontalContentAlignmentProperty As DependencyProperty =
DependencyProperty.Register("HorizontalContentAlignment", GetType(TextAlignment), GetType(EgtTextBox), New FrameworkPropertyMetadata(New PropertyChangedCallback(AddressOf TextAlignment_PropertyChanged)) With {.BindsTwoWayByDefault = True})
Public Overloads Property HorizontalContentAlignment As TextAlignment
Get
Return CType(GetValue(HorizontalContentAlignmentProperty), TextAlignment)
End Get
Set(value As TextAlignment)
SetValue(HorizontalContentAlignmentProperty, value)
End Set
End Property
Public Shared ReadOnly TextAlignmentProperty As DependencyProperty =
DependencyProperty.Register("TextAlignment", GetType(TextAlignment), GetType(EgtTextBox), New FrameworkPropertyMetadata(New PropertyChangedCallback(AddressOf TextAlignment_PropertyChanged)) With {.BindsTwoWayByDefault = True})
Public Property TextAlignment As TextAlignment
Get
Return CType(GetValue(TextAlignmentProperty), TextAlignment)
End Get
Set(value As TextAlignment)
SetValue(TextAlignmentProperty, value)
End Set
End Property
Public Shared ReadOnly TextWrappingProperty As DependencyProperty =
DependencyProperty.Register("TextWrapping", GetType(TextWrapping), GetType(EgtTextBox), New FrameworkPropertyMetadata(New PropertyChangedCallback(AddressOf TextWrapping_PropertyChanged)) With {.BindsTwoWayByDefault = True})
Public Property TextWrapping As TextWrapping
Get
Return CType(GetValue(TextWrappingProperty), TextWrapping)
End Get
Set(value As TextWrapping)
SetValue(TextWrappingProperty, value)
End Set
End Property
Public Shared ReadOnly TextCharacterCasingProperty As DependencyProperty =
DependencyProperty.Register("CharacterCasing", GetType(CharacterCasing), GetType(EgtTextBox), New FrameworkPropertyMetadata(New PropertyChangedCallback(AddressOf TextWrapping_PropertyChanged)))
Public Property CharacterCasing As CharacterCasing
Get
Return CType(GetValue(TextCharacterCasingProperty), CharacterCasing)
End Get
Set(value As CharacterCasing)
SetValue(TextCharacterCasingProperty, value)
End Set
End Property
'------------------------------------------ START NEW MANAGE INTERFACE ------------------------------------------
#Region "NEW MANAGE INTERFACE "
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~GESTIONE BACKGROUDBRDENABLE TEXTBOX~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Public Shared ReadOnly BackgroundBrdEnableProperty As DependencyProperty = DependencyProperty.RegisterAttached(
NameOf(BackgroundBrdEnable),
GetType(Brush),
GetType(EgtTextBox),
New FrameworkPropertyMetadata(DirectCast(New BrushConverter().ConvertFromString("#FFFFFF"), Brush),
New PropertyChangedCallback(AddressOf BackgroundBrdEnable_PropertyChanged)) With {.BindsTwoWayByDefault = True})
' Declare a get accessor method.
Public Shared Function GetBackgroundBrdEnable(element As EgtTextBox) As Brush
Return DirectCast(element.GetValue(BackgroundBrdEnableProperty), Brush)
End Function
' Declare a set accessor method.
Public Shared Sub SetBackgroundBrdEnable(element As EgtTextBox, value As Brush)
element.SetValue(BackgroundBrdEnableProperty, value)
End Sub
' Declare public property.
Public Property BackgroundBrdEnable As Brush
Get
Return CType(GetValue(BackgroundBrdEnableProperty), Brush)
End Get
Set(value As Brush)
SetValue(BackgroundBrdEnableProperty, value)
End Set
End Property
' Declare method invoke by changing property.
Private Shared Sub BackgroundBrdEnable_PropertyChanged(sender As DependencyObject, e As DependencyPropertyChangedEventArgs)
Dim TempMe As EgtTextBox = DirectCast(sender, EgtTextBox)
End Sub
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~GESTIONE BACKGROUNDBRDDISABLE TEXTBOX~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Public Shared ReadOnly BackgroundBrdDisableProperty As DependencyProperty = DependencyProperty.RegisterAttached(
NameOf(BackgroundBrdDisable),
GetType(Brush),
GetType(EgtTextBox),
New FrameworkPropertyMetadata(DirectCast(New BrushConverter().ConvertFromString("#FFFFFF"), Brush),
New PropertyChangedCallback(AddressOf BackgroundBrdDisable_PropertyChanged)) With {.BindsTwoWayByDefault = True})
' Declare a get accessor method.
Public Shared Function GetBackgroundBrdDisableProperty(element As EgtTextBox) As Brush
Return DirectCast(element.GetValue(BackgroundBrdDisableProperty), Brush)
End Function
' Declare a set accessor method.
Public Shared Sub SetBackgroundBrdDisableProperty(element As EgtTextBox, value As Brush)
element.SetValue(BackgroundBrdDisableProperty, value)
End Sub
' Declare public property.
Public Property BackgroundBrdDisable As Brush
Get
Return CType(GetValue(BackgroundBrdDisableProperty), Brush)
End Get
Set(value As Brush)
SetValue(BackgroundBrdDisableProperty, value)
End Set
End Property
' Declare method invoke by changing property.
Private Shared Sub BackgroundBrdDisable_PropertyChanged(sender As DependencyObject, e As DependencyPropertyChangedEventArgs)
Dim TempMe As EgtTextBox = DirectCast(sender, EgtTextBox)
End Sub
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~GESTIONE BORDERBRUSHISMOUSEOVER TEXTBOX~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Public Shared ReadOnly BorderBrushIsMouseOverProperty As DependencyProperty = DependencyProperty.RegisterAttached(
NameOf(BorderBrushIsMouseOver),
GetType(Brush),
GetType(EgtTextBox),
New FrameworkPropertyMetadata(DirectCast(New BrushConverter().ConvertFromString("#7EB4EA"), Brush),
New PropertyChangedCallback(AddressOf BorderBrushIsMouseOver_PropertyChanged)) With {.BindsTwoWayByDefault = True})
' Declare a get accessor method.
Public Shared Function GetBorderBrushIsMouseOverProperty(element As EgtTextBox) As Brush
Return DirectCast(element.GetValue(BorderBrushIsMouseOverProperty), Brush)
End Function
' Declare a set accessor method.
Public Shared Sub SetBorderBrushIsMouseOverProperty(element As EgtTextBox, value As Brush)
element.SetValue(BorderBrushIsMouseOverProperty, value)
End Sub
' Declare public property.
Public Property BorderBrushIsMouseOver As Brush
Get
Return CType(GetValue(BorderBrushIsMouseOverProperty), Brush)
End Get
Set(value As Brush)
SetValue(BorderBrushIsMouseOverProperty, value)
End Set
End Property
' Declare method invoke by changing property.
Private Shared Sub BorderBrushIsMouseOver_PropertyChanged(sender As DependencyObject, e As DependencyPropertyChangedEventArgs)
Dim TempMe As EgtTextBox = DirectCast(sender, EgtTextBox)
End Sub
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~GESTIONE BORDERBRUSHISMOUSEFOCUSED TEXTBOX~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Public Shared ReadOnly BorderBrushIsFocusedProperty As DependencyProperty = DependencyProperty.RegisterAttached(
NameOf(BorderBrushIsFocused),
GetType(Brush),
GetType(EgtTextBox),
New FrameworkPropertyMetadata(DirectCast(New BrushConverter().ConvertFromString("#569DE5"), Brush),
New PropertyChangedCallback(AddressOf BorderBrushIsFocused_PropertyChanged)) With {.BindsTwoWayByDefault = True})
' Declare a get accessor method.
Public Shared Function GetBorderBrushIsFocusedProperty(element As EgtTextBox) As Brush
Return DirectCast(element.GetValue(BorderBrushIsFocusedProperty), Brush)
End Function
' Declare a set accessor method.
Public Shared Sub SetBorderBrushIsFocusedProperty(element As EgtTextBox, value As Brush)
element.SetValue(BorderBrushIsFocusedProperty, value)
End Sub
' Declare public property.
Public Property BorderBrushIsFocused As Brush
Get
Return CType(GetValue(BorderBrushIsFocusedProperty), Brush)
End Get
Set(value As Brush)
SetValue(BorderBrushIsFocusedProperty, value)
End Set
End Property
' Declare method invoke by changing property.
Private Shared Sub BorderBrushIsFocused_PropertyChanged(sender As DependencyObject, e As DependencyPropertyChangedEventArgs)
Dim TempMe As EgtTextBox = DirectCast(sender, EgtTextBox)
End Sub
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~GESTIONE BORDERBRUSH TEXTBOX~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' "#ABAdB3"
Public Shared ReadOnly GeneralBorderBrushProperty As DependencyProperty = DependencyProperty.RegisterAttached(
NameOf(GeneralBorderBrush),
GetType(Brush),
GetType(EgtTextBox),
New FrameworkPropertyMetadata(DirectCast(New BrushConverter().ConvertFromString("#CFD1D4"), Brush),
New PropertyChangedCallback(AddressOf GeneralBorderBrush_PropertyChanged)) With {.BindsTwoWayByDefault = True})
' Declare a get accessor method.
Public Shared Function GetGeneralBorderBrush(element As EgtTextBox) As Brush
Return DirectCast(element.GetValue(GeneralBorderBrushProperty), Brush)
End Function
' Declare a set accessor method.
' Declare a set accessor method.
Public Shared Sub SetGeneralBorderBrush(element As EgtTextBox, value As Brush)
element.SetValue(GeneralBorderBrushProperty, value)
End Sub
' Declare public property.
Public Property GeneralBorderBrush As Brush
Get
Return CType(GetValue(GeneralBorderBrushProperty), Brush)
End Get
Set(value As Brush)
SetValue(GeneralBorderBrushProperty, value)
End Set
End Property
' Declare method invoke by changing property.
Private Shared Sub GeneralBorderBrush_PropertyChanged(sender As DependencyObject, e As DependencyPropertyChangedEventArgs)
Dim TempMe As EgtTextBox = DirectCast(sender, EgtTextBox)
End Sub
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~GESTIONE BACKGROUNDTXBLDISABLE TEXTBOX~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Public Shared ReadOnly BackgroundTxBlDisableProperty As DependencyProperty = DependencyProperty.RegisterAttached(
NameOf(BackgroundTxBlDisable),
GetType(Brush),
GetType(EgtTextBox),
New FrameworkPropertyMetadata(DirectCast(New BrushConverter().ConvertFromString("#FFFFFF"), Brush),
New PropertyChangedCallback(AddressOf BackgroundTxBlDisable_PropertyChanged)) With {.BindsTwoWayByDefault = True})
' Declare a get accessor method.
Public Shared Function GetBackgroundTxBlDisableProperty(element As EgtTextBox) As Brush
Return DirectCast(element.GetValue(BackgroundTxBlDisableProperty), Brush)
End Function
' Declare a set accessor method.
Public Shared Sub SetBackgroundTxBlDisableProperty(element As EgtTextBox, value As Brush)
element.SetValue(BackgroundTxBlDisableProperty, value)
End Sub
' Declare public property.
Public Property BackgroundTxBlDisable As Brush
Get
Return CType(GetValue(BackgroundTxBlDisableProperty), Brush)
End Get
Set(value As Brush)
SetValue(BackgroundTxBlDisableProperty, value)
End Set
End Property
' Declare method invoke by changing property.
Private Shared Sub BackgroundTxBlDisable_PropertyChanged(sender As DependencyObject, e As DependencyPropertyChangedEventArgs)
Dim TempMe As EgtTextBox = DirectCast(sender, EgtTextBox)
End Sub
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~GESTIONE FOREGROUNDTXBLENABLE TEXTBOX~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Public Shared ReadOnly ForegroundTxBlEnableProperty As DependencyProperty = DependencyProperty.RegisterAttached(
NameOf(ForegroundTxBlEnable),
GetType(Brush),
GetType(EgtTextBox),
New FrameworkPropertyMetadata(SystemColors.WindowTextBrush, New PropertyChangedCallback(AddressOf ForegroundTxBlEnable_PropertyChanged)) With {.BindsTwoWayByDefault = True})
' Declare a get accessor method.
Public Shared Function GetForegroundTxBlEnableProperty(element As EgtTextBox) As Brush
Return DirectCast(element.GetValue(ForegroundTxBlEnableProperty), Brush)
End Function
' Declare a set accessor method.
Public Shared Sub SetForegroundTxBlEnableProperty(element As EgtTextBox, value As Brush)
element.SetValue(ForegroundTxBlEnableProperty, value)
End Sub
' Declare public property.
Public Property ForegroundTxBlEnable As Brush
Get
Return CType(GetValue(ForegroundTxBlEnableProperty), Brush)
End Get
Set(value As Brush)
SetValue(ForegroundTxBlEnableProperty, value)
End Set
End Property
' Declare method invoke by changing property.
Private Shared Sub ForegroundTxBlEnable_PropertyChanged(sender As DependencyObject, e As DependencyPropertyChangedEventArgs)
Dim TempMe As EgtTextBox = DirectCast(sender, EgtTextBox)
End Sub
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~GESTIONE FOREGROUNDTXBLDISABLE TEXTBOX~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Public Shared ReadOnly ForegroundTxBlDisableProperty As DependencyProperty = DependencyProperty.RegisterAttached(
NameOf(ForegroundTxBlDisable),
GetType(Brush),
GetType(EgtTextBox),
New FrameworkPropertyMetadata(SystemColors.WindowTextBrush, New PropertyChangedCallback(AddressOf ForegroundTxBlDisable_PropertyChanged)) With {.BindsTwoWayByDefault = True})
' Declare a get accessor method.
Public Shared Function GetForegroundTxBlDisableProperty(element As EgtTextBox) As Brush
Return DirectCast(element.GetValue(ForegroundTxBlDisableProperty), Brush)
End Function
' Declare a set accessor method.
Public Shared Sub SetForegroundTxBlDisableProperty(element As EgtTextBox, value As Brush)
element.SetValue(ForegroundTxBlDisableProperty, value)
End Sub
' Declare public property.
Public Property ForegroundTxBlDisable As Brush
Get
Return CType(GetValue(ForegroundTxBlDisableProperty), Brush)
End Get
Set(value As Brush)
SetValue(ForegroundTxBlDisableProperty, value)
End Set
End Property
' Declare method invoke by changing property.
Private Shared Sub ForegroundTxBlDisable_PropertyChanged(sender As DependencyObject, e As DependencyPropertyChangedEventArgs)
Dim TempMe As EgtTextBox = DirectCast(sender, EgtTextBox)
End Sub
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~GESTIONE FOREGROUNDCOLOR TEXTBOX~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Public Shared ReadOnly GeneralForegroundProperty As DependencyProperty = DependencyProperty.RegisterAttached(
NameOf(GeneralForeground),
GetType(Brush),
GetType(EgtTextBox),
New FrameworkPropertyMetadata(SystemColors.WindowTextBrush, New PropertyChangedCallback(AddressOf GeneralForeground_PropertyChanged)) With {.BindsTwoWayByDefault = True})
' Declare a get accessor method.
Public Shared Function GetGeneralForeground(element As EgtTextBox) As Brush
Return DirectCast(element.GetValue(GeneralForegroundProperty), Brush)
End Function
' Declare a set accessor method.
Public Shared Sub SetGeneralForeground(element As EgtTextBox, value As Brush)
element.SetValue(GeneralForegroundProperty, value)
End Sub
' Declare public property.
Public Property GeneralForeground As Brush
Get
Return CType(GetValue(GeneralForegroundProperty), Brush)
End Get
Set(value As Brush)
SetValue(GeneralForegroundProperty, value)
End Set
End Property
' Declare method invoke by changing property.
Private Shared Sub GeneralForeground_PropertyChanged(sender As DependencyObject, e As DependencyPropertyChangedEventArgs)
Dim TempMe As EgtTextBox = DirectCast(sender, EgtTextBox)
End Sub
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~GESTIONE BACKGROUNDCOLOR TEXTBOX~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Public Shared ReadOnly GeneralBackgroundProperty As DependencyProperty = DependencyProperty.RegisterAttached(
NameOf(GeneralBackground),
GetType(Brush),
GetType(EgtTextBox),
New FrameworkPropertyMetadata(DirectCast(New BrushConverter().ConvertFromString("#FFFFFF"), Brush),
New PropertyChangedCallback(AddressOf GeneralBackground_PropertyChanged)) With {.BindsTwoWayByDefault = True})
' Declare a get accessor method.
Public Shared Function GetGeneralBackgroun(element As EgtTextBox) As Brush
Return DirectCast(element.GetValue(GeneralBackgroundProperty), Brush)
End Function
' Declare a set accessor method.
Public Shared Sub SetGeneralBackgroun(element As EgtTextBox, value As Brush)
element.SetValue(GeneralBackgroundProperty, value)
End Sub
' Declare public property.
Public Property GeneralBackground As Brush
Get
Return CType(GetValue(GeneralBackgroundProperty), Brush)
End Get
Set(value As Brush)
SetValue(GeneralBackgroundProperty, value)
End Set
End Property
' Declare method invoke by changing property.
Private Shared Sub GeneralBackground_PropertyChanged(sender As DependencyObject, e As DependencyPropertyChangedEventArgs)
Dim TempMe As EgtTextBox = DirectCast(sender, EgtTextBox)
End Sub
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~GESTIONE CHARACTERCASING TEXTBOX~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Public Shared ReadOnly MyCharacterCasingProperty As DependencyProperty = DependencyProperty.RegisterAttached(
NameOf(MyCharacterCasing),
GetType(String),
GetType(EgtTextBox),
New FrameworkPropertyMetadata("Normal", New PropertyChangedCallback(AddressOf MyCharacterCasing_PropertyChanged)) With {.BindsTwoWayByDefault = True})
' Declare a get accessor method.
Public Shared Function GetMyCharacterCasing(element As EgtTextBox) As String
Return DirectCast(element.GetValue(MyCharacterCasingProperty), String)
End Function
' Declare a set accessor method.
Public Shared Sub SetMyCharacterCasing(element As EgtTextBox, value As String)
element.SetValue(MyCharacterCasingProperty, value)
End Sub
' Declare public property.
Public Property MyCharacterCasing As String
Get
Return CType(GetValue(MyCharacterCasingProperty), String)
End Get
Set(value As String)
SetValue(MyCharacterCasingProperty, value)
End Set
End Property
' Declare method invoke by changing property.
Private Shared Sub MyCharacterCasing_PropertyChanged(sender As DependencyObject, e As DependencyPropertyChangedEventArgs)
Dim TempMe As EgtTextBox = DirectCast(sender, EgtTextBox)
End Sub
#End Region ' New Manage Interface
'------------------------------------------ FINISH NEW MANAGE INTERFACE ------------------------------------------
Private Shared Sub Text_PropertyChanged(sender As DependencyObject, e As DependencyPropertyChangedEventArgs)
Dim TempMe As EgtTextBox = DirectCast(sender, EgtTextBox)
If TempMe.ActiveTextBox Then
TempMe.TxBx.Text = CStr(e.NewValue)
Else
TempMe.TxBl.Text = CStr(e.NewValue)
End If
End Sub
Private Shared Sub TextAlignment_PropertyChanged(sender As DependencyObject, e As DependencyPropertyChangedEventArgs)
Dim TempMe As EgtTextBox = DirectCast(sender, EgtTextBox)
TempMe.TxBl.TextAlignment = CType(e.NewValue, TextAlignment)
TempMe.TxBx.TextAlignment = CType(e.NewValue, TextAlignment)
End Sub
Private Shared Sub VerticalAlignment_PropertyChanged(sender As DependencyObject, e As DependencyPropertyChangedEventArgs)
Dim TempMe As EgtTextBox = DirectCast(sender, EgtTextBox)
TempMe.TxBl.VerticalAlignment = CType(e.NewValue, VerticalAlignment)
TempMe.TxBx.VerticalContentAlignment = CType(e.NewValue, VerticalAlignment)
' Il Padding di TxBx è settato a "1,1,1,0" ma quando VerticalContentAlignment è "Center" o "Bottom" occorre incrementare il Bottom
' del Padding a 1 settandolo dunque a "1,1,1,1". In questo modo l'allineamento del testo tra TxBl e TxBx è garantito.
If TempMe.TxBx.VerticalContentAlignment = VerticalAlignment.Center Or TempMe.TxBx.VerticalContentAlignment = VerticalAlignment.Bottom Then
TempMe.TxBx.Padding = New Thickness(1, 1, 1, 1)
End If
End Sub
Private Shared Sub IsReadOnly_PropertyChanged(sender As DependencyObject, e As DependencyPropertyChangedEventArgs)
Dim TempMe As EgtTextBox = DirectCast(sender, EgtTextBox)
TempMe.TxBx.IsReadOnly = CBool(e.NewValue)
End Sub
Private Shared Sub TextWrapping_PropertyChanged(sender As DependencyObject, e As DependencyPropertyChangedEventArgs)
Dim TempMe As EgtTextBox = DirectCast(sender, EgtTextBox)
TempMe.TxBx.TextWrapping = CType(e.NewValue, TextWrapping)
TempMe.TxBl.TextWrapping = CType(e.NewValue, TextWrapping)
End Sub
Private Shared Sub TextCharacterCasing_PropertyChanged(sender As DependencyObject, e As DependencyPropertyChangedEventArgs)
Dim TempMe As EgtTextBox = DirectCast(sender, EgtTextBox)
TempMe.TxBx.CharacterCasing = CType(e.NewValue, CharacterCasing)
' TempMe.TxBl.CharacterCasing = CType(e.NewValue, CharacterCasing)
End Sub
Private Sub TxBx_TextChanged(sender As Object, e As TextChangedEventArgs) Handles TxBx.TextChanged
Text = TxBx.Text
End Sub
'Used to track whether Or Not this TextBox is active.
Private ActiveTextBox As Boolean = False
' Use to track if some exiting event is fired
Private m_bSuspendLostKeyboardFocus As Boolean = False
Private m_bSuspendLostFocus As Boolean = False
'Activates the hit TextBox if it isn't active.
'Deactivates the active TextBox if something else was hit.
Sub Me_MouseLeftButtonDown(sender As Object, e As MouseButtonEventArgs) Handles Me.MouseDown
If Not ActiveTextBox Then
Activate()
Dim eMouseDown As New MouseButtonEventArgs(e.MouseDevice, e.Timestamp, e.ChangedButton, e.StylusDevice)
eMouseDown.RoutedEvent = e.RoutedEvent
eMouseDown.Source = TxBx
TxBx.RaiseEvent(eMouseDown)
End If
End Sub
'Deactivates the active TextBox if the Enter Or ESC key Is pressed.
Sub HandleKeyInput(sender As Object, args As KeyEventArgs)
If ActiveTextBox And (args.Key = Key.Return Or args.Key = Key.Escape) Then Deactivate()
End Sub
'Deactivate the Textbox if it's active.
Sub HandleLostFocus(sender As Object, e As RoutedEventArgs)
If ActiveTextBox AndAlso Not m_bSuspendLostFocus Then
m_bSuspendLostFocus = True
Deactivate()
m_bSuspendLostFocus = False
End If
End Sub
Sub HandleLostKeyboardFocus(sender As Object, e As KeyboardFocusChangedEventArgs)
If ActiveTextBox AndAlso Not m_bSuspendLostKeyboardFocus AndAlso Not m_bSuspendLostFocus Then
m_bSuspendLostFocus = True
If Not Me.IsReadOnly Then
If ExplicitUpdateSource = UpdateSourceType.EnterKeyPress Then
Me.GetBindingExpression(EgtTextBox.TextProperty).UpdateSource()
End If
End If
Deactivate()
m_bSuspendLostFocus = False
End If
End Sub
'Activate the TextBox by changing Visibility and copying text from the TextBlock to the TextBox.
'Set focus, Select all the content & invalidate the visual.
'Also, dynamically add handlers for losing focus And handling key input.
Sub Activate()
If ActiveTextBox Then Return
Brd.Visibility = Visibility.Hidden
TxBl.Visibility = Visibility.Hidden
TxBx.Visibility = Visibility.Visible
TxBx.Text = TxBl.Text
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, Sub()
'Keyboard.Focus(Me.TxBx)
Me.TxBx.Focus()
Me.TxBx.InvalidateVisual()
End Sub)
AddHandler Me.LostFocus, New RoutedEventHandler(AddressOf HandleLostFocus)
AddHandler Me.LostKeyboardFocus, New KeyboardFocusChangedEventHandler(AddressOf HandleLostKeyboardFocus)
AddHandler Me.KeyDown, New KeyEventHandler(AddressOf HandleKeyInput)
ActiveTextBox = True
End Sub
'Deactivate the TextBox by changing Visibility, deselecting the selected text and copying text from the TextBox to the TextBlock.
'Remove the event handlers.
Sub Deactivate()
If Not ActiveTextBox Then Return
Brd.Visibility = Visibility.Visible
TxBl.Visibility = Visibility.Visible
TxBx.SelectionLength = 0
TxBx.Visibility = Visibility.Hidden
TxBl.Text = TxBx.Text
RemoveHandler Me.LostFocus, New RoutedEventHandler(AddressOf HandleLostFocus)
RemoveHandler Me.LostKeyboardFocus, New KeyboardFocusChangedEventHandler(AddressOf HandleLostKeyboardFocus)
RemoveHandler Me.KeyDown, New KeyEventHandler(AddressOf HandleKeyInput)
ActiveTextBox = False
End Sub
#Region "EgtTextBox originale"
' Proprietà che permette di impostare l'altezza della TitleBar
Public Shared ReadOnly ExplicitUpdateSourceProperty As DependencyProperty = DependencyProperty.Register("ExplicitUpdateSource", GetType(UpdateSourceType), GetType(EgtTextBox), New PropertyMetadata(UpdateSourceType.Null))
Public Property ExplicitUpdateSource() As UpdateSourceType
Get
Return DirectCast(GetValue(ExplicitUpdateSourceProperty), UpdateSourceType)
End Get
Set(ByVal value As UpdateSourceType)
SetValue(ExplicitUpdateSourceProperty, value)
End Set
End Property
Public Shared ReadOnly IsExplicitFocusedProperty As DependencyProperty = DependencyProperty.Register("IsExplicitFocused", GetType(Boolean), GetType(EgtTextBox), New UIPropertyMetadata(False, AddressOf OnIsFocusedPropertyChanged))
Public Property IsExplicitFocused() As Boolean
Get
Return CBool(GetValue(IsExplicitFocusedProperty))
End Get
Set(ByVal value As Boolean)
Me.Focus()
SetValue(IsExplicitFocusedProperty, value)
End Set
End Property
Public Enum UpdateSourceType As Integer
Null = 0
PropertyChanged = 1
EnterKeyPress = 2
End Enum
Private Shared Sub OnIsFocusedPropertyChanged(d As DependencyObject, e As DependencyPropertyChangedEventArgs)
If CBool(e.NewValue) Then
Dim CurrEgtTextBox As EgtTextBox = TryCast(d, EgtTextBox)
If Not IsNothing(CurrEgtTextBox) Then
If Not CurrEgtTextBox.ActiveTextBox Then
CurrEgtTextBox.Activate()
End If
End If
End If
End Sub
Private Sub EgtTextBox_PreviewKeyDown(sender As Object, e As System.Windows.Input.KeyEventArgs) Handles Me.PreviewKeyDown
If (e.Key = Key.Enter OrElse e.Key = Key.Escape) AndAlso Not Me.IsReadOnly Then
m_bSuspendLostKeyboardFocus = True
If ExplicitUpdateSource = UpdateSourceType.EnterKeyPress Then
Me.GetBindingExpression(EgtTextBox.TextProperty).UpdateSource()
End If
Keyboard.ClearFocus()
Deactivate()
m_bSuspendLostKeyboardFocus = False
End If
End Sub
Private Sub EgtTextBox_TextChanged(sender As Object, e As System.Windows.Controls.TextChangedEventArgs) Handles TxBx.TextChanged 'Me.TextChanged
If ExplicitUpdateSource = UpdateSourceType.PropertyChanged Then
Me.GetBindingExpression(EgtTextBox.TextProperty).UpdateSource()
End If
End Sub
#End Region
End Class