I have a converter that provides a default value for empty strings. Apparently you can't add a binding to the ConverterParameter so I add a property to the converter, which I bind to instead.
However, the value I'm getting back for the default property is a string of "System.Windows.Data.Binding" instead of my value.
How do I resolve this binding in code so I can return the real localized string I want?
Here's my converter class (based on answer https://stackoverflow.com/a/15567799/250254):
public class DefaultForNullOrWhiteSpaceStringConverter : IValueConverter
{
public object Default { set; get; }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (!string.IsNullOrWhiteSpace((string)value))
{
return value;
}
else
{
if (parameter != null)
{
return parameter;
}
else
{
return this.Default;
}
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
}
And my 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}}" />
Any ideas?