33 lines
839 B
C#
33 lines
839 B
C#
using System;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Controls.Templates;
|
|
using Valheim_Dashboard.ViewModels;
|
|
|
|
namespace Valheim_Dashboard;
|
|
|
|
public class ViewLocator : IDataTemplate
|
|
{
|
|
public Control? Build(object? param)
|
|
{
|
|
if (param is null)
|
|
return null;
|
|
|
|
var viewModelType = param.GetType();
|
|
var name = viewModelType.FullName!.Replace("ViewModel", "View", StringComparison.Ordinal);
|
|
|
|
// Verwenden Sie die Assembly des ViewModels, um die View zu finden
|
|
var viewType = viewModelType.Assembly.GetType(name);
|
|
|
|
|
|
if (viewType != null)
|
|
{
|
|
return (Control)Activator.CreateInstance(viewType)!;
|
|
}
|
|
|
|
return new TextBlock { Text = "Not Found: " + name };
|
|
}
|
|
public bool Match(object? data)
|
|
{
|
|
return data is ViewModelBase;
|
|
}
|
|
} |