使用Silverlight 4中的帮助程序类的DataBinding错误

时间:2011-01-05 13:34:41

标签: c# silverlight data-binding silverlight-4.0

我是整个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.    

这个错误允许项目编译,绑定工作,但它很烦人。 你能帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

{Binding}和其他此类标记扩展的使用是硬连接到Xaml解析器中的。你不能“自己动手”。

在我看来,您正在尝试在Silverlight应用中创建本地化框架。查看此问题的答案Best Practices For Silverlight Localization?