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
|
|
|
|
2023-11-15 03:09:50 +00:00
|
|
|
public Control Build(object? data)
|
2021-10-23 16:51:17 +00:00
|
|
|
{
|
2022-11-12 05:31:37 +00:00
|
|
|
var name = data!.GetType().FullName!.Replace("ViewModel", "View");
|
2021-10-23 16:51:17 +00:00
|
|
|
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
|
|
|
|
2022-11-12 05:31:37 +00:00
|
|
|
public bool Match(object? data)
|
2021-10-23 16:51:17 +00:00
|
|
|
{
|
|
|
|
return data is ViewModelBase;
|
2021-10-08 13:16:51 +00:00
|
|
|
}
|
|
|
|
}
|