This commit is contained in:
2024-05-20 22:25:19 -04:00
parent ce92bfd7f2
commit 45926fbfca
26 changed files with 242 additions and 31 deletions

27
ToDoList/ViewLocator.cs Normal file
View File

@@ -0,0 +1,27 @@
using System;
using Avalonia.Controls;
using Avalonia.Controls.Templates;
using ToDoList.ViewModels;
namespace ToDoList;
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;
}
}