From e84db09bd6d0e3ab24258cb8ded4112badcd6d90 Mon Sep 17 00:00:00 2001 From: doyaGu Date: Sat, 3 Oct 2026 22:47:37 -0400 Subject: [PATCH] fix(view-locator): show the missing-view placeholder through a resource key PLAN 8.1 forbids hard-coded UI text; the template's ViewLocator still built "Not Found: " in code. --- YKanBan/Assets/Locales/Resources.resx | 3 +++ YKanBan/Assets/Locales/Resources.zh-Hans.resx | 3 +++ YKanBan/ViewLocator.cs | 27 ++++++++++--------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/YKanBan/Assets/Locales/Resources.resx b/YKanBan/Assets/Locales/Resources.resx index 5a09083..e954f47 100644 --- a/YKanBan/Assets/Locales/Resources.resx +++ b/YKanBan/Assets/Locales/Resources.resx @@ -343,6 +343,9 @@ The change could not be written to the workspace. The board shows the stored state. + + View not found: {0} + Reading failed diff --git a/YKanBan/Assets/Locales/Resources.zh-Hans.resx b/YKanBan/Assets/Locales/Resources.zh-Hans.resx index 31320d4..3a99db3 100644 --- a/YKanBan/Assets/Locales/Resources.zh-Hans.resx +++ b/YKanBan/Assets/Locales/Resources.zh-Hans.resx @@ -343,6 +343,9 @@ 更改未能写入工作区,看板显示的是已保存的状态。 + + 找不到视图:{0} + 读取失败 diff --git a/YKanBan/ViewLocator.cs b/YKanBan/ViewLocator.cs index 651f07e..4de99af 100644 --- a/YKanBan/ViewLocator.cs +++ b/YKanBan/ViewLocator.cs @@ -1,31 +1,34 @@ -using System; using Avalonia.Controls; using Avalonia.Controls.Templates; using YKanBan.ViewModels; namespace YKanBan; +/// +/// Resolves the view of a view model by naming convention: the type name with +/// "ViewModel" replaced by "View". A missing view is a programming error; it +/// shows a localized placeholder naming the type that was looked for. +/// 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) + string name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal); + Type? type = Type.GetType(name); + if (type is not null) { return (Control)Activator.CreateInstance(type)!; } - - return new TextBlock { Text = "Not Found: " + name }; + + return new TextBlock { Text = string.Format(YKanBan.Resources.Culture, YKanBan.Resources.Error_ViewNotFound, name) }; } - public bool Match(object? data) - { - return data is ViewModelBase; - } + /// + public bool Match(object? data) => data is ViewModelBase; }