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.
This commit is contained in:
1 parent
8714eec6ca
commit
e84db09bd6
3 files changed
+21
-12
No files matched your search
@@ -343,6 +343,9 @@
|
|||||||
<data name="Error_Operation_Message" xml:space="preserve">
|
<data name="Error_Operation_Message" xml:space="preserve">
|
||||||
<value>The change could not be written to the workspace. The board shows the stored state.</value>
|
<value>The change could not be written to the workspace. The board shows the stored state.</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Error_ViewNotFound" xml:space="preserve">
|
||||||
|
<value>View not found: {0}</value>
|
||||||
|
</data>
|
||||||
<data name="Error_Read_Title" xml:space="preserve">
|
<data name="Error_Read_Title" xml:space="preserve">
|
||||||
<value>Reading failed</value>
|
<value>Reading failed</value>
|
||||||
</data>
|
</data>
|
||||||
|
|||||||
@@ -343,6 +343,9 @@
|
|||||||
<data name="Error_Operation_Message" xml:space="preserve">
|
<data name="Error_Operation_Message" xml:space="preserve">
|
||||||
<value>更改未能写入工作区,看板显示的是已保存的状态。</value>
|
<value>更改未能写入工作区,看板显示的是已保存的状态。</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Error_ViewNotFound" xml:space="preserve">
|
||||||
|
<value>找不到视图:{0}</value>
|
||||||
|
</data>
|
||||||
<data name="Error_Read_Title" xml:space="preserve">
|
<data name="Error_Read_Title" xml:space="preserve">
|
||||||
<value>读取失败</value>
|
<value>读取失败</value>
|
||||||
</data>
|
</data>
|
||||||
|
|||||||
+15
-12
@@ -1,31 +1,34 @@
|
|||||||
using System;
|
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Controls.Templates;
|
using Avalonia.Controls.Templates;
|
||||||
using YKanBan.ViewModels;
|
using YKanBan.ViewModels;
|
||||||
|
|
||||||
namespace YKanBan;
|
namespace YKanBan;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
public class ViewLocator : IDataTemplate
|
public class ViewLocator : IDataTemplate
|
||||||
{
|
{
|
||||||
|
/// <inheritdoc/>
|
||||||
public Control? Build(object? param)
|
public Control? Build(object? param)
|
||||||
{
|
{
|
||||||
if (param is null)
|
if (param is null)
|
||||||
|
{
|
||||||
return 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 (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)
|
/// <inheritdoc/>
|
||||||
{
|
public bool Match(object? data) => data is ViewModelBase;
|
||||||
return data is ViewModelBase;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user