summary refs log tree commit diff
path: root/BatchBeatmapDownloader/ViewLocator.cs
blob: e22d6528c3b1185dfbbfce7b626088bc0da9b030 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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;
	}
}