-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewLocator.vb
More file actions
28 lines (24 loc) · 1.01 KB
/
Copy pathViewLocator.vb
File metadata and controls
28 lines (24 loc) · 1.01 KB
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
Imports System
Imports Avalonia.Controls
Imports Avalonia.Controls.Templates
Imports Avalonia.Media
Imports FerrumPix.ViewModels
Public Class ViewLocator
Implements IDataTemplate
Public Function Build(param As Object) As Control Implements IDataTemplate.Build
Dim fullName = param.GetType().FullName
If fullName Is Nothing Then Return New TextBlock With {.Text = "Typ-Fehler"}
Dim viewName = fullName.Replace("FerrumPix.ViewModels.", "FerrumPix.Views.").Replace("ViewModel", "View")
Dim viewType = Type.GetType(viewName)
If viewType IsNot Nothing Then
Return CType(Activator.CreateInstance(viewType), Control)
End If
Return New TextBlock With {
.Text = "View nicht gefunden: " & viewName,
.Foreground = New SolidColorBrush(Color.Parse("#FF6060"))
}
End Function
Public Function Match(data As Object) As Boolean Implements IDataTemplate.Match
Return TypeOf data Is ViewModelBase
End Function
End Class