2023-08-21 18:57:48 -04:00
|
|
|
|
using Avalonia.Controls;
|
2023-05-11 23:11:39 -04:00
|
|
|
|
using Avalonia.Controls.Templates;
|
|
|
|
|
using SPTInstaller.ViewModels;
|
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
namespace SPTInstaller;
|
|
|
|
|
|
|
|
|
|
public class ViewLocator : IDataTemplate
|
2023-05-11 23:11:39 -04:00
|
|
|
|
{
|
2023-08-21 18:57:48 -04:00
|
|
|
|
public Control Build(object data)
|
2023-05-11 23:11:39 -04:00
|
|
|
|
{
|
2023-07-12 09:19:33 +02:00
|
|
|
|
var name = data.GetType().FullName!.Replace("ViewModel", "View");
|
|
|
|
|
var type = Type.GetType(name);
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
if (type != null)
|
2023-05-11 23:11:39 -04:00
|
|
|
|
{
|
2023-07-12 09:19:33 +02:00
|
|
|
|
return (Control)Activator.CreateInstance(type)!;
|
2023-05-11 23:11:39 -04:00
|
|
|
|
}
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
return new TextBlock { Text = "Not Found: " + name };
|
|
|
|
|
}
|
2024-05-01 10:31:55 -04:00
|
|
|
|
|
2023-07-12 09:19:33 +02:00
|
|
|
|
public bool Match(object data)
|
|
|
|
|
{
|
|
|
|
|
return data is ViewModelBase;
|
2023-05-11 23:11:39 -04:00
|
|
|
|
}
|
|
|
|
|
}
|