You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
766 B
C#
31 lines
766 B
C#
using Avalonia.Controls;
|
|
using Avalonia.Controls.Templates;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using System;
|
|
|
|
namespace Sln.Wcs.UI;
|
|
|
|
public class ViewLocator : IDataTemplate
|
|
{
|
|
public Control? Build(object? param)
|
|
{
|
|
if (param is null)
|
|
return new TextBlock { Text = "DataContext is null" };
|
|
|
|
var viewName = param.GetType().FullName!
|
|
.Replace("ViewModels", "Views")
|
|
.Replace("ViewModel", "Window");
|
|
|
|
var type = Type.GetType(viewName);
|
|
if (type is null)
|
|
return new TextBlock { Text = $"View not found: {viewName}" };
|
|
|
|
return (Control)Activator.CreateInstance(type)!;
|
|
}
|
|
|
|
public bool Match(object? data)
|
|
{
|
|
return data is ObservableObject;
|
|
}
|
|
}
|