特定の文字の書式だけ変更する Run
<TextBlock>~</TextBlock>で囲まれた文字のうち、特定の文字だけ書式を変えるには、その文字を<Run>~</Run>で括り、<Run>タグにFontFamilyやForegroundなどの属性を指定します。または、書式を変えたい文字を<Run>タグのText属性で指定します。次が<Run>のサンプルです。
http://www.makoto3.net/xaml/silverlight0058/index.html
【myxaml.xaml】
<Canvas
xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<TextBlock Canvas.Left="10" Canvas.Top="10" Width="280" TextWrapping="Wrap" Foreground="navy">
Silverlight is
<Run Foreground="red" FontFamily="Courier New" FontSize="24">very</Run>
exciting technology.But Silverlight 1.0 cannot handle
<Run Foreground="Blue" FontFamily="Arial" FontSize="40" FontWeight="ExtraBold" FontStyle="Italic">Japanese.</Run>
<Run TextDecorations="underline">Silverlight 2.0</Run>
will can handle Japanese.
</TextBlock>
<TextBlock Canvas.Left="10" Canvas.Top="160" Width="280" TextWrapping="Wrap" Foreground="green" Text="Silverlight is ">
<Run Foreground="red" FontFamily="Courier New" FontSize="24" Text="very"/>
<Run Text="exciting technology.But Silverlight 1.0 cannot handle "/>
<Run Foreground="Blue" FontFamily="Arial" FontSize="40" FontWeight="ExtraBold" FontStyle="Italic" Text="Japanese."/>
<Run TextDecorations="Underline" Text="Silverlight 2.0"/>
<Run Text="will can handle Japanese."/>
</TextBlock>
</Canvas>
上のサンプルの赤い記述は、表示する文字を<Run>~</Run>で括った例、青い記述は表示する文字をText属性で指定した例です。書き方が異なるだけで、結果は同じです。
指定できる属性は、<TextBlock>とほぼ同じと考えよさそうです(Canvas.LeftやWidth、TextWrappingなどはありません)。なお、上記サンプルでは、TextDecorations属性で下線を指定しています。
|
TextDecorations |
文字に下線を設定する。
|
このページは
xfy Blog Editor
を利用して作成されました。










コメント