Comment cacher StringFormat si les données sont null
-
03-10-2019 - |
Question
Comment cacher un StringFormat lorsque les données ne sont pas present.Consider cet échantillon
<TextBlock Text="{Binding Amount, StringFormat=Total: {0:C}}" />
Dans ce cas, si le montant est nul, alors il affichera seulement Total: .Comment cacher si le montant est nul ou vide
La solution 2
« TargetNullValue » est ce que je recherchais for.I a fini avec cela et cela a fonctionné comme un charme
<TextBlock VerticalAlignment="Top"
Text="{Binding Path=TotalMonths,
TargetNullValue={x:Static System:String.Empty},
StringFormat=Total: {0:C}}" />
Autres conseils
TargetNullValue=''
Fera aussi
Il n'y a pas grand-chose à travailler avec, mais vous pouvez obtenir quelque chose comme ceci avec:
- DataTrigger
- ValueConverter
- EventHandling dans le code-behind
- La liaison sur un (dependency-) dans une propriété ViewModel encapsulant vos classes d'affaires
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow