我看不出有任何方法可以用 TargetNullValue 做到这一点。作为一种解决方法,您可以尝试使用转换器:
public class NullValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null)
{
return value;
}
var resourceName = (string)parameter;
return AppResources.ResourceManager.GetString(resourceName);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
然后将其添加到页面的资源中:
<phone:PhoneApplicationPage.Resources>
<local:NullValueConverter x:Key="NullValueConverter" />
</phone:PhoneApplicationPage.Resources>
最后,使用它代替 TargetNullValue:
<TextBlock Text="{Binding DueDate, Converter={StaticResource NullValueConverter}, ConverterParameter=bt_help_Title1}" />