我是整个 Silverlight 的新手。遇到了问题
我有一个派生自 Binding the Localizer 的类,声明如下:
public class Localizer : Binding
{
public Localizer()
{
}
private string _key;
/// <summary>
/// Localization key manager.
/// </summary>
public string Key
{
get { return _key; }
set
{
_key = value;
Source = LocalizationHelper.Current;
Path = new PropertyPath("Translations["+_key+"]");
}
}
}
当我在 XAML 页面中使用它时
<p:BasePage x:Class="Project.Pages.Desktop"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:h="clr-namespace:Project.Helpers">
<TextBlock Controls:DockPanel.Dock="Top" Text="{h:Localizer Key=UI_DSKTP_NAME}"/>
我遇到了一个错误
Type 'h:Localizer' is used like a markup extension but does not derive from MarkupExtension.
此错误允许项目编译和绑定(bind),但很烦人。 你能帮我解决这个问题吗?
最佳答案
{Binding} 和其他此类标记扩展的使用已硬连接到 Xaml 解析器中。你不能“自己动手”。
在我看来,您正试图在 Silverlight 应用程序中创建本地化框架。查看此问题的答案 Best Practices For Silverlight Localization? .
关于c# - 在 Silverlight 4 错误中使用帮助程序类进行数据绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4604602/