From 5a5a07c7fad31641d032a743e4e87ffb58ade17d Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Fri, 22 May 2026 22:10:19 +0800 Subject: Initial commit --- rola-desktop/ViewLocator.cs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 rola-desktop/ViewLocator.cs (limited to 'rola-desktop/ViewLocator.cs') diff --git a/rola-desktop/ViewLocator.cs b/rola-desktop/ViewLocator.cs new file mode 100644 index 0000000..eec4713 --- /dev/null +++ b/rola-desktop/ViewLocator.cs @@ -0,0 +1,31 @@ +using System; +using Avalonia.Controls; +using Avalonia.Controls.Templates; +using rola_desktop.ViewModels; + +namespace rola_desktop; + +public class ViewLocator : IDataTemplate +{ + + public Control? Build(object? param) + { + if (param is null) + return null; + + var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal); + 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; + } +} -- cgit