21 lines
600 B
C#
21 lines
600 B
C#
using System;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Controls.Templates;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
namespace Lagerprogramm;
|
|
|
|
public class ViewLocator : IDataTemplate
|
|
{
|
|
public Control? Build(object? param)
|
|
{
|
|
if (param is null) return null;
|
|
var name = param.GetType().FullName!.Replace("ViewModel", "View");
|
|
var type = Type.GetType(name);
|
|
if (type is null) return new TextBlock { Text = $"Not Found: {name}" };
|
|
return (Control)Activator.CreateInstance(type)!;
|
|
}
|
|
|
|
public bool Match(object? data) => data is ObservableObject;
|
|
}
|