Hide <Run /> tag in TextBlock - WPF

Visibility is the property in the UIElement class which all UI controls derive from but Run doesn't derive from it.

Best you can do is to set Text property to String.Empty in code behind:

bottomRun.Text = String.Empty;

You can user Style Trigger with Binding :

<Run>
    <Run.Style>
        <Style TargetType="Run">
            <Setter Property="Text" Value="Bottom text"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=variable}" Value="{x:Null}">
                    <Setter Property="Text" Value=""/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Run.Style>
</Run>

The TextBlock you've got is pretty small. When faced with a similar situation, I duplicated it and bound the Visiblity property on TextBlock.

<TextBlock Visibility="{Binding Path=LicenseValid, Converter={StaticResource BooleanToVisibilityConverter}, ConverterParameter=false }">
      <Run Text="TopText"/>
      <LineBreak/>
      <Run x:Name="bottomRun" Text="Bottom text"/>
  </TextBlock>

<TextBlock Visibility="{Binding Path=LicenseValid, Converter={StaticResource BooleanToVisibilityConverter}, ConverterParameter=false }">
      <Run Text="TopText"/>
      <LineBreak/>
      <Run x:Name="bottomRun" Text="Bottom text"/>
  </TextBlock>

The converter is suitably declared, defined and takes an 'invert' parameter.

Tags:

Wpf