This repository has been archived by the owner on Jan 31, 2024. It is now read-only.
/
TypeBasedEditorTemplateSelector.vb
51 lines (42 loc) · 2.03 KB
/
TypeBasedEditorTemplateSelector.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Imports DevExpress.Xpf.Printing
Imports DevExpress.XtraPrinting
Imports System
Imports System.Globalization
Imports System.Windows
Imports System.Windows.Data
Imports System.Windows.Markup
Namespace CustomEditingFieldsSelector
Public Class TypeBasedEditorTemplateSelector
Inherits EditingFieldTemplateSelector
Public Property Int32Template() As DataTemplate
Public Property DateTimeTemplate() As DataTemplate
Public Property EnumTemplate() As DataTemplate
Public Overrides Function SelectTemplate(ByVal item As Object, ByVal container As DependencyObject) As DataTemplate
Dim field = TryCast(item, EditingField)
If field.EditValue IsNot Nothing AndAlso TypeOf field.EditValue Is System.Enum Then
Return EnumTemplate
ElseIf TypeOf field.EditValue Is Date Then
Return DateTimeTemplate
ElseIf TypeOf field.EditValue Is Int32 Then
Return Int32Template
End If
Return MyBase.SelectTemplate(item, container)
End Function
End Class
Public Class EnumValueToEnumSourceConverter
Inherits MarkupExtension
Implements IValueConverter
Public Overrides Function ProvideValue(ByVal serviceProvider As IServiceProvider) As Object
Return Me
End Function
Private Function IValueConverter_Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As CultureInfo) As Object Implements IValueConverter.Convert
If Not (TypeOf value Is System.Enum) Then
Throw New InvalidOperationException()
End If
Return System.Enum.GetValues(value.GetType())
End Function
Private Function IValueConverter_ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As CultureInfo) As Object Implements IValueConverter.ConvertBack
Throw New NotSupportedException()
End Function
End Class
End Namespace