mirror of
https://github.com/BeyondDimension/SteamTools.git
synced 2026-10-20 00:11:04 +08:00
33 lines
969 B
C#
33 lines
969 B
C#
using Avalonia.Controls;
|
|
using Avalonia.Controls.Templates;
|
|
using System.Application.UI.ViewModels;
|
|
|
|
namespace System.Application.UI
|
|
{
|
|
public class ViewLocator : IDataTemplate
|
|
{
|
|
#pragma warning disable CA1822 // 将成员标记为 static
|
|
public bool SupportsRecycling => false;
|
|
#pragma warning restore CA1822 // 将成员标记为 static
|
|
|
|
public IControl Build(object data)
|
|
{
|
|
var name = data.GetType().FullName?.Replace("ViewModel", "View");
|
|
var type = name == null ? null : Type.GetType(name);
|
|
if (type != null)
|
|
{
|
|
var view = (Control?)Activator.CreateInstance(type);
|
|
if (view != null)
|
|
{
|
|
return view;
|
|
}
|
|
}
|
|
return new TextBlock { Text = "Not Found: " + name };
|
|
}
|
|
|
|
public bool Match(object data)
|
|
{
|
|
return data is ViewModelBase;
|
|
}
|
|
}
|
|
} |