wpf - How to set a default empty binding unless the value is different from 0? -
when set binding <textblock text="{binding position}"..> ui gives 0 int defaults 0. first, how stop showing result unless position not 0 ? second, if position = 5, ui shows result, if goes 0 again, stop showing result again
in c#, int value type, meaning can never null. can use nullable<int> transform nullable, defaults null.
a shortcut question mark. if define position int? position should result you're after.
edit: didn't see request value disappearing after position = 0 again.
a alternative use ivalueconverter proposed in comments.
otherwise, use trigger, so:
<style targettype="textblock" text="{binding position}"> <style.triggers> <trigger property="text" value="0"> <setter property="visibility" value="collapsed" /> </trigger> </style.triggers> </style>
Comments
Post a Comment