Programmatically change the way in which TextBlock is trimmed when it exceeds the outer boundaries of its containing box. : TextBlock « Windows Presentation Foundation « VB.Net Tutorial






<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Class="WpfApplication1.Window1"
  Title="TextTrimming Sample">
    <DockPanel Margin="10">
      <StackPanel Orientation="Horizontal" DockPanel.Dock="Top" Margin="0,0,0,25">
        <Button Click="ttNone">TextTrimming="None"</Button>
        <Button Click="ttCE">TextTrimming="CharacterEllipsis"</Button>
        <Button Click="ttWE">TextTrimming="WordEllipsis"</Button>
      </StackPanel>
      <TextBlock Name="txt1" DockPanel.Dock="Bottom"/>
      <TextBlock HorizontalAlignment="Left" TextWrapping="NoWrap" 
        Width="400" FontFamily="Arial" Name="tf1" DockPanel.Dock="Top"
        Background="SkyBlue">
        Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt
        laoreet dolore magna aliquam erat volutpat.
      </TextBlock>
    </DockPanel>
</Window>


//File:Window.xaml.vb
Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents

Namespace WpfApplication1
  Public Partial Class Window1
    Inherits Window
    Public Sub ttNone(sender As Object, e As RoutedEventArgs)
      tf1.TextTrimming = System.Windows.TextTrimming.None
      txt1.Text = "TextTrimming is now " + tf1.TextTrimming.ToString()
    End Sub
    Public Sub ttCE(sender As Object, e As RoutedEventArgs)
      tf1.TextTrimming = System.Windows.TextTrimming.CharacterEllipsis
      txt1.Text = "TextTrimming is now " + tf1.TextTrimming.ToString()
    End Sub
    Public Sub ttWE(sender As Object, e As RoutedEventArgs)
      tf1.TextTrimming = System.Windows.TextTrimming.WordEllipsis
      txt1.Text = "TextTrimming is now " + tf1.TextTrimming.ToString()
    End Sub
  End Class
End Namespace
WPF Programmatically Change The Way In Which Text Block Is Trimmed When It Exceeds The Outer Boundaries Of Its Containing Box








16.1.TextBlock
16.1.1.Simple TextBlockSimple TextBlock
16.1.2.Simple contentSimple content
16.1.3.LineBreak inside a TextBlockLineBreak inside a TextBlock
16.1.4.Semi-Transparent TextBlockSemi-Transparent TextBlock
16.1.5.TextBlock.Foreground and ImageBrushTextBlock.Foreground and ImageBrush
16.1.6.Multi-span for TextBlockMulti-span for TextBlock
16.1.7.Setting text decorationsSetting text decorations
16.1.8.Set pen for TextDecorationsSet pen for TextDecorations
16.1.9.TextTrimming for TextBlockTextTrimming for TextBlock
16.1.10.Layout TextBlock in UniformGridLayout TextBlock in UniformGrid
16.1.11.Text as contentText as content
16.1.12.Text with mixed contentText with mixed content
16.1.13.Whitespace as content and as attributeWhitespace as content and as attribute
16.1.14.Preserving whitespace in mixed contentPreserving whitespace in mixed content
16.1.15.Nested TextBlockNested TextBlock
16.1.16.Enabling hyphenationEnabling hyphenation
16.1.17.Positioning a hosted Button element with BaselineAlignment along with textPositioning a hosted Button element with BaselineAlignment along with text
16.1.18.Using RenderTransformUsing RenderTransform
16.1.19.This is rotating textThis is rotating text
16.1.20.Handling overflowHandling overflow
16.1.21.Use Run the mark underlink TextDecorationsUse Run the mark underlink TextDecorations
16.1.22.Simple underline decorationSimple underline decoration
16.1.23.Effects of the enumerated values of TextWrapping.Effects of the enumerated values of TextWrapping.
16.1.24.Programmatically change the way in which TextBlock is trimmed when it exceeds the outer boundaries of its containing box.Programmatically change the way in which TextBlock is trimmed when it exceeds the outer boundaries of its containing box.