I have what I thought was a simple requirement, but I'm having difficulty working out how to do it.
I'm binding to an address (Line1, Line2, Line3, Line4 for example)
What I want to do is display
Line1
Line2
Line3
Line4
But if any line is empty or null, I'd like to 'collapse':
Line1
Line3
Line4
I've tried a StackPanel with TextBlocks - but I haven't worked out how to get the TextBlocks to 'disappear' if they're empty.
<StackPanel>
<TextBlock Text="{Binding Line1}"></TextBlock>
<TextBlock Text="{Binding Line2}"></TextBlock>
<TextBlock Text="{Binding Line3}"></TextBlock>
<TextBlock Text="{Binding Line4}"></TextBlock>
</StackPanel>
I've also tried MultiBinding, but I can't work out how to get a newline in the StringFormat.
<TextBlock>
<TextBlock.Text>
<!-- Doesn't work: "System.FormatException" -->
<MultiBinding StringFormat="{}{1}\n{2}\n{3}\n{4}">
<Binding Path="Line1"/>
<Binding Path="Line2"/>
<Binding Path="Line3"/>
<Binding Path="Line4"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
Any ideas?