When you are using StringFormat in XAML, if the data is null, the oputput will be just the format text.
For example, consider the following example.
<TextBlock Text="{Binding Path=Amount, StringFormat=Total: {0:C}}" />
When the Amount is null, the output of the above binding will be "Total:" This doesn't makes any sense. So, most of teh cases, you have to hide the text or display alternative text. You can achive this with converters (IValueConverter).
There is another simple way to do it without writing any C# code using TargetNullValue. Here is how you can achieve the result.
<TextBlock Text="{Binding Path=Amount,
TargetNullValue={x:Static System:String.Empty},
StringFormat=Total: {0:C}}" />
Note:-
If you are using TargetNullValue in Binding, if the value is null, it will ignore the StringFormat. In some cases, you might want to display the Text with formatted string. In this case, you cannot use the above mentioned method. you have to implement your converter.
33d34598-3ebc-4b63-811c-b560b757c281|1|5.0
.Net Tips, .Net, wpf
TargetNullValue, StringFormat, WPF