wabbajack/Wabbajack.Launcher/ViewLocator.cs

26 lines
631 B
C#
Raw Normal View History

2021-10-08 13:16:51 +00:00
using System;
using Avalonia.Controls;
using Avalonia.Controls.Templates;
using Wabbajack.Launcher.ViewModels;
2021-10-23 16:51:17 +00:00
namespace Wabbajack.Launcher;
public class ViewLocator : IDataTemplate
2021-10-08 13:16:51 +00:00
{
2021-10-23 16:51:17 +00:00
public bool SupportsRecycling => false;
2021-10-08 13:16:51 +00:00
2021-10-23 16:51:17 +00:00
public IControl Build(object data)
{
var name = data.GetType().FullName!.Replace("ViewModel", "View");
var type = Type.GetType(name);
2021-10-08 13:16:51 +00:00
2021-10-23 16:51:17 +00:00
if (type != null)
return (Control) Activator.CreateInstance(type)!;
return new TextBlock {Text = "Not Found: " + name};
}
2021-10-08 13:16:51 +00:00
2021-10-23 16:51:17 +00:00
public bool Match(object data)
{
return data is ViewModelBase;
2021-10-08 13:16:51 +00:00
}
}