【问题标题】:DataBinding using helper class in Silverlight 4 Error在 Silverlight 4 错误中使用帮助程序类的 DataBinding
【发布时间】:2011-01-05 13:34:40
【问题描述】:

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

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

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-06
      • 1970-01-01
      • 2016-01-08
      相关资源
      最近更新 更多