summaryrefslogtreecommitdiff
path: root/rola-desktop/ViewLocator.cs
diff options
context:
space:
mode:
Diffstat (limited to 'rola-desktop/ViewLocator.cs')
-rw-r--r--rola-desktop/ViewLocator.cs31
1 files changed, 31 insertions, 0 deletions
diff --git a/rola-desktop/ViewLocator.cs b/rola-desktop/ViewLocator.cs
new file mode 100644
index 0000000..eec4713
--- /dev/null
+++ b/rola-desktop/ViewLocator.cs
@@ -0,0 +1,31 @@
+using System;
+using Avalonia.Controls;
+using Avalonia.Controls.Templates;
+using rola_desktop.ViewModels;
+
+namespace rola_desktop;
+
+public class ViewLocator : IDataTemplate
+{
+
+ public Control? Build(object? param)
+ {
+ if (param is null)
+ return null;
+
+ var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal);
+ var type = Type.GetType(name);
+
+ if (type != null)
+ {
+ return (Control)Activator.CreateInstance(type)!;
+ }
+
+ return new TextBlock { Text = "Not Found: " + name };
+ }
+
+ public bool Match(object? data)
+ {
+ return data is ViewModelBase;
+ }
+}