I have 3 textblocks in a stackpanel in a DataTemplate.
the idea is that the format should be like “a b c” with spaces between the textblocks but it may happen that textblocks “a” and “b” might be empty, so i end up with something like this ” c” ( two spaces before textblock c). How can i ensure that i have a margin but only if there is content?
If the
TextBlock‘sVisibilityis set toCollapsed, theMarginwill not be shown. So I guess you can use aStringToVisibilityConverterto set itsVisibilitytoCollapsedif theTextis empty.Example
First you need to create a converter like this.
Then you need to include this converter into your xaml.
Finally, use it inside your
TextBlock.For more info regarding how to use a converter, please take a look at this post.
Hope it helps. 🙂