Search code examples
wpf

Hide <Run /> tag in TextBlock - WPF


I have textblock with 2 Run tags and one Linebreak:

  <TextBlock>
      <Run Text="TopText"/>
      <LineBreak/>
      <Run x:Name="bottomRun" Text="Bottom text"/>
  </TextBlock>

I want to hide second Run tag in code behind. But there is no Visible property... Why is it so? What is the best solution how to hide only one Run tag?


Solution

  • 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;