From bef1d59cffaae749661d0a5d90914839a54cc8e7 Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Mon, 9 Oct 2023 00:26:46 +0200 Subject: Initial commit --- BatchBeatmapDownloader/ViewLocator.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 BatchBeatmapDownloader/ViewLocator.cs (limited to 'BatchBeatmapDownloader/ViewLocator.cs') 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; + } +} -- cgit 1.5.1