26 lines
582 B
C#
Raw Normal View History

2023-05-11 23:11:39 -04:00
using Avalonia.Controls;
using Avalonia.Controls.Templates;
using SPTInstaller.ViewModels;
namespace SPTInstaller;
public class ViewLocator : IDataTemplate
2023-05-11 23:11:39 -04:00
{
public IControl Build(object data)
2023-05-11 23:11:39 -04:00
{
var name = data.GetType().FullName!.Replace("ViewModel", "View");
var type = Type.GetType(name);
2023-05-11 23:11:39 -04:00
if (type != null)
2023-05-11 23:11:39 -04:00
{
return (Control)Activator.CreateInstance(type)!;
2023-05-11 23:11:39 -04:00
}
return new TextBlock { Text = "Not Found: " + name };
}
public bool Match(object data)
{
return data is ViewModelBase;
2023-05-11 23:11:39 -04:00
}
}