WPF的TextBlock控件
XMAL代码如下:
<Window x:Class="MyControl.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MyControl"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="500">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Margin="10" Foreground="Red" Grid.Row="0" HorizontalAlignment="Center" FontSize="20">
This is a textblock control<LineBreak/>
this is second line
</TextBlock>
<TextBlock Margin="10" Foreground="Green" Grid.Row="1" HorizontalAlignment="Left">
This is a TextBlock control with text that may not be rendered completely, which will be indicated with an ellipsis.
</TextBlock>
<TextBlock Grid.Row="2" TextWrapping="Wrap" Foreground="Blue">
This is a TextBlock control with automatically wrapped text, using the TextWrapping property.
</TextBlock>
<TextBlock Grid.Row="3" TextWrapping="Wrap" Foreground="Black">
<Bold>this is a bold line</Bold><LineBreak/>
<Italic>this is a italic line</Italic><LineBreak/>
<Underline>this is a underLine word</Underline><LineBreak/>
<Hyperlink RequestNavigate="Hyperlink_RequestNavigate" NavigateUri="https://www.baidu.com">Click me to navigate to Baidu</Hyperlink>
</TextBlock>
<TextBlock Grid.Row="4">
This <Span FontWeight="Bold" FontSize="20" Foreground="Blue">is</Span>
a <Span FontSize="10" TextDecorations="Underline">line</Span>
using <Span FontStyle="Italic" FontSize="15" Foreground="Red">custom</Span> span !
</TextBlock>
</Grid>
</Window>