È necessario creare un convertitore per questo, che implementa IValueConverter
public class StringEmptyConverter : IValueConverter {
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
return string.IsNullOrEmpty((string)value) ? parameter : value;
}
public object ConvertBack(
object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
throw new NotSupportedException();
}
}
Poi in XAML si era appena fornire il convertitore per la rilegatura, (xxx
rappresenta solo il tuo Window
/UserControl
/Style
... dove il legame è)
<xxx.Resources>
<local:StringEmptyConverter x:Key="StringEmptyConverter" />
</xxx.Resources>
<TextBlock Text="{Binding Name, Converter={StaticResource StringEmptyConverter}, ConverterParameter='Placeholder Text'}" />
c'è una risposta molto semplice a [inserire descrizione collegamento qui] [1] [1] : http://stackoverflow.com/questions/16612622/give-textblock-default-value-if-result-returns-null – FLICKER
c'è una soluzione molto semplice a [Valore predefinito TextBox se i rendimenti di rilegatura null] [1] [1]: http://stackoverflow.com/questions/16612622/give-textblock-default-value-if-result-returns- null – FLICKER