Programmatically change the way in which TextBlock is trimmed when it exceeds the outer boundaries of its containing box.



<Window xmlns=""
  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>
      <TextBlock Name="txt1" DockPanel.Dock="Bottom"/>
      <TextBlock HorizontalAlignment="Left" TextWrapping="NoWrap" 
        Width="400" FontFamily="Arial" Name="tf1" DockPanel.Dock="Top"
        Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt
        laoreet dolore magna aliquam erat volutpat.

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;

namespace WpfApplication1
  public partial class Window1 : Window
        public void ttNone(object sender, RoutedEventArgs e)
            tf1.TextTrimming = System.Windows.TextTrimming.None;
            txt1.Text = "TextTrimming is now " + tf1.TextTrimming.ToString();
        public void ttCE(object sender, RoutedEventArgs e)
            tf1.TextTrimming = System.Windows.TextTrimming.CharacterEllipsis;
            txt1.Text = "TextTrimming is now " + tf1.TextTrimming.ToString();
        public void ttWE(object sender, RoutedEventArgs e)
            tf1.TextTrimming = System.Windows.TextTrimming.WordEllipsis;
            txt1.Text = "TextTrimming is now " + tf1.TextTrimming.ToString();