summary refs log tree commit diff
path: root/BatchBeatmapDownloader/ViewLocator.cs
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-10-09 00:26:46 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-10-09 00:26:46 +0200
commitbef1d59cffaae749661d0a5d90914839a54cc8e7 (patch)
treea05a726d27567bed093e77c194b1e0f9d2ac700f /BatchBeatmapDownloader/ViewLocator.cs
downloadBatchBeatmapDownloader-master.tar.xz
Initial commit HEAD master
Diffstat (limited to 'BatchBeatmapDownloader/ViewLocator.cs')
-rw-r--r--BatchBeatmapDownloader/ViewLocator.cs23
1 files changed, 23 insertions, 0 deletions
diff --git a/BatchBeatmapDownloader/ViewLocator.cs b/BatchBeatmapDownloader/ViewLocator.cs
new file mode 100644
index 0000000..e22d652
--- /dev/null
+++ b/BatchBeatmapDownloader/ViewLocator.cs
@@ -0,0 +1,23 @@
+using System;
+using Avalonia.Controls;
+using Avalonia.Controls.Templates;
+using BatchBeatmapDownloader.ViewModels;
+
+namespace BatchBeatmapDownloader;
+
+public class ViewLocator : IDataTemplate {
+	public Control Build(object data) {
+		var name = data.GetType().FullName!.Replace("ViewModel", "View");
+		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;
+	}
+}