diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-06-17 21:33:40 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-06-17 21:57:13 +0800 |
| commit | ad0943f88ba9f5ed6eae198ecb4835c0f44701de (patch) | |
| tree | 6a8eb1fee42e7ee173e74788dafeb27c52429683 /rola-desktop/ViewLocator.cs | |
chore: initialize project structure and add core modules
Diffstat (limited to 'rola-desktop/ViewLocator.cs')
| -rw-r--r-- | rola-desktop/ViewLocator.cs | 31 |
1 files changed, 31 insertions, 0 deletions
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; + } +} |
