How to collapse databound TextBlock
Hello,
I'd like to set the "Visibility" property of a databound TextBlock based on whether there is any content or not. In the following example, there is an empty XML element<Department>, so the TextBlock in row 2 should be collapsed. What is the simplest way to do this? What is the simplest way to do this?
Thanks,
Adrian
<FixedPage
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="21cm" Height="29.7cm">
<FixedPage.Resources>
<XmlDataProvider x:Key="AddressData" XPath="CustomerAddress">
<x:XData>
<CustomerAddress xmlns="">
<Company>Company Name</Company>
<Department></Department>
<Name>Recipient Name</Name>
<Street>Musterstrasse 123</Street>
<City>9876 Hintertupfiken</City>
<Country>SWITZERLAND</Country>
</CustomerAddress>
</x:XData>
</XmlDataProvider>
</FixedPage.Resources>
<!-- CustomerAddress Grid-->
<Grid FixedPage.Left="2cm" FixedPage.Top="5cm" TextBlock.FontSize="12pt"
ShowGridLines="True"
DataContext="{Binding Mode=OneTime, Source={StaticResource AddressData}}">
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="Billing Address:" LineHeight="48" FontWeight="Bold"/>
<TextBlock Grid.Row="1" Text="{Binding XPath=Company}"/>
<!-- since the "Department" element is empty, the textblock / grid row shuld be COLLAPSED -->
<TextBlock Grid.Row="2" Text="{Binding XPath=Department}"/>
<TextBlock Grid.Row="3" Text="{Binding XPath=Name}"/>
<TextBlock Grid.Row="4" Text="{Binding XPath=Street}"/>
<TextBlock Grid.Row="5" Text="{Binding XPath=City}"/>
<TextBlock Grid.Row="6" Text="{Binding XPath=Country}"/>
</Grid>
</FixedPage>

