be8dbbb0f4
- Aggiunta Db utensili e lavorazioni. - Aggiunta finestra di SetUp. - Aggiunte molte funzioni di utilità generale. - Migliorie varie.
107 lines
4.4 KiB
VB.net
107 lines
4.4 KiB
VB.net
' Follow steps 1a or 1b and then 2 to use this custom control in a XAML file.
|
|
'
|
|
' Step 1a) Using this custom control in a XAML file that exists in the current project.
|
|
' Add this XmlNamespace attribute to the root element of the markup file where it is
|
|
' to be used:
|
|
'
|
|
' xmlns:MyNamespace="clr-namespace:EgtWPFLib5"
|
|
'
|
|
'
|
|
' Step 1b) Using this custom control in a XAML file that exists in a different project.
|
|
' Add this XmlNamespace attribute to the root element of the markup file where it is
|
|
' to be used:
|
|
'
|
|
' xmlns:MyNamespace="clr-namespace:EgtWPFLib5;assembly=EgtWPFLib5"
|
|
'
|
|
' You will also need to add a project reference from the project where the XAML file lives
|
|
' to this project and Rebuild to avoid compilation errors:
|
|
'
|
|
' Right click on the target project in the Solution Explorer and
|
|
' "Add Reference"->"Projects"->[Browse to and select this project]
|
|
'
|
|
'
|
|
' Step 2)
|
|
' Go ahead and use your control in the XAML file. Note that Intellisense in the
|
|
' XML editor does not currently work on custom controls and its child elements.
|
|
'
|
|
' <MyNamespace:EgtTextBox/>
|
|
'
|
|
|
|
Imports System.Windows.Controls.Primitives
|
|
Imports System.ComponentModel
|
|
|
|
Public Class EgtTextBox
|
|
Inherits System.Windows.Controls.TextBox
|
|
|
|
' 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
|
|
|
|
Shared Sub New()
|
|
'This OverrideMetadata call tells the system that this element wants to provide a style that is different than its base class.
|
|
'This style is defined in themes\generic.xaml
|
|
DefaultStyleKeyProperty.OverrideMetadata(GetType(EgtTextBox), New FrameworkPropertyMetadata(GetType(EgtTextBox)))
|
|
End Sub
|
|
|
|
Private Shared Sub OnIsFocusedPropertyChanged(d As DependencyObject, e As DependencyPropertyChangedEventArgs)
|
|
Dim uie = DirectCast(d, UIElement)
|
|
uie.Focus()
|
|
End Sub
|
|
|
|
Private Sub EgtTextBox_PreviewKeyDown(sender As Object, e As System.Windows.Input.KeyEventArgs) Handles Me.PreviewKeyDown
|
|
If e.Key = Key.Enter Then
|
|
If ExplicitUpdateSource = UpdateSourceType.EnterKeyPress Then
|
|
Me.GetBindingExpression(TextBox.TextProperty).UpdateSource()
|
|
End If
|
|
Keyboard.ClearFocus()
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub EgtTextBox_TextChanged(sender As Object, e As System.Windows.Controls.TextChangedEventArgs) Handles Me.TextChanged
|
|
If ExplicitUpdateSource = UpdateSourceType.PropertyChanged Then
|
|
Me.GetBindingExpression(TextBox.TextProperty).UpdateSource()
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub ExplicitBindingTextBox_Loaded(sender As Object, e As RoutedEventArgs)
|
|
Dim textBox As TextBox = TryCast(sender, TextBox)
|
|
|
|
If TryCast(textBox.DataContext, INotifyPropertyChanged) Is Nothing Then
|
|
Throw New InvalidOperationException("...")
|
|
End If
|
|
|
|
AddHandler TryCast(textBox.DataContext, INotifyPropertyChanged).PropertyChanged, AddressOf ViewModel_PropertyChanged
|
|
End Sub
|
|
|
|
Private Sub ViewModel_PropertyChanged(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs)
|
|
If ExplicitUpdateSource = UpdateSourceType.PropertyChanged Or ExplicitUpdateSource = UpdateSourceType.EnterKeyPress Then
|
|
Me.GetBindingExpression(TextBox.TextProperty).UpdateTarget()
|
|
End If
|
|
End Sub
|
|
|
|
End Class
|