<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.cs
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();
}
}
}
|