C# 通过Windows Phone 8上的代码解析XAML绑定

C# 通过Windows Phone 8上的代码解析XAML绑定,c#,xaml,windows-phone-8,ivalueconverter,C#,Xaml,Windows Phone 8,Ivalueconverter,我有一个为空字符串提供默认值的转换器。显然,您无法向ConverterParameter添加绑定,因此我向转换器添加了一个属性,而我将其绑定 但是,我为默认属性返回的值是“System.Windows.Data.Binding”字符串,而不是我的值 如何在代码中解析此绑定,以便返回所需的真正本地化字符串 以下是我的转换器类(基于答案): 还有我的XAML: <phone:PhoneApplicationPage.Resources> <tc:DefaultForNull

我有一个为空字符串提供默认值的转换器。显然,您无法向ConverterParameter添加绑定,因此我向转换器添加了一个属性,而我将其绑定

但是,我为默认属性返回的值是“System.Windows.Data.Binding”字符串,而不是我的值

如何在代码中解析此绑定,以便返回所需的真正本地化字符串

以下是我的转换器类(基于答案):

还有我的XAML:

<phone:PhoneApplicationPage.Resources>
    <tc:DefaultForNullOrWhiteSpaceStringConverter x:Key="WaypointNameConverter"
        Default="{Binding Path=LocalizedResources.Waypoint_NoName, Mode=OneTime, Source={StaticResource LocalizedStrings}}" />
</phone:PhoneApplicationPage.Resources>

<TextBlock Text="{Binding Name, Converter={StaticResource WaypointNameConverter}}" />


有什么想法吗?

现在,我已经通过从转换器继承并在构造函数中设置本地化字符串解决了这个问题。然而,我觉得必须有一个更优雅的解决方案来解决我的问题,允许直接使用基极转换器

public class WaypointNameConverter : DefaultForNullOrWhiteSpaceStringConverter
{
    public WaypointNameConverter()
    {
        base.Default = Resources.AppResources.Waypoint_NoName;
    }
}

您应该能够通过继承并将
Default
属性更改为默认属性来实现这一点


谢谢你的编辑,很抱歉它被拒绝了,因为它是一个正确的编辑!不用担心-我想我应该编辑代码,让其他有同样问题的人的生活更轻松;)
public class WaypointNameConverter : DefaultForNullOrWhiteSpaceStringConverter
{
    public WaypointNameConverter()
    {
        base.Default = Resources.AppResources.Waypoint_NoName;
    }
}
public class DefaultForNullOrWhiteSpaceStringConverter : DependencyObject, IValueConverter
{
    public string DefaultValue
    {
        get { return (string)GetValue(DefaultValueProperty); }
        set { SetValue(DefaultValueProperty, value); }
    }

    // Using a DependencyProperty as the backing store for DefaultValue.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty DefaultValueProperty =
        DependencyProperty.Register("DefaultValue", typeof(string), 
        typeof(DefaultForNullOrWhiteSpaceStringConverter), new PropertyMetadata(null));
...
...