astel-labs.net

C#などのプログラミングTipsや雑記をつらつらと書くかもしれないブログです。

  • Home
RSS

WPF – 文字の縁取り方法

Posted on 2011年1月20日 by Nymphaea
No CommentsLeave a comment

昨年末からずっと、SharePoint 2007 から SharePoint 2010 への移行作業に追われ、開発にいたころ以来久しぶりの忙しさでした・・・(まだ作業は終わっていませんけど)

うちの会社はIT系企業ではないので、そもそも SharePoint で必要とされるソフトウェア関連の知識を持った人が乏しい為、Office InfoPath のフォームの作成から、データベースの構築、データアクセス用 web サービスの作成、サーバーファーム構成を含めたネットワーク構成の構築、IISサーバー設定と、ほぼすべての作業を1人でする羽目に・・・

外部に出せば数百万円する作業をこなしているわたしに、会社はボーナスを出せばいいと思います!!

 

 

とまあ、わたしの愚痴は置いといて(今回の記事は書くことがあまりなかったので・・・)、
SharePoint でウンウンと頭を悩ませているとき、別の調べものの最中に偶然見つけたサンプルコードに、いままでずっと頭を悩ませていた文字の縁取りに使える手法を見つけました!
(むしろ、なぜ気づかなかった? というレベルの内容です・・・)

ともあれ、サンプルで書いたコードを実行するとこんな感じになります

↑正しくはドロップシャドウです・・・ もちろんワザとですよ?

 

 

 

考え方は、単純に同じサイズの TextBlock を4方向に少しずつずらして重ね合わせているだけです

画像などに文字を表示する際には見やすくなると思います

 

以下はサンプルコード
SyntaxHighlighter がもう少し見やすく Xaml コードを表示してくれるといいのですが・・・

 

<StackPanel Orientation="Vertical">
    <Grid>
        <TextBlock Text="{Binding ElementName=test1, Path=Text}" Foreground="Black" FontSize="{Binding ElementName=test1, Path=FontSize}">
            <TextBlock.RenderTransform>
                <TranslateTransform X="2" Y="2" />
            </TextBlock.RenderTransform>
        </TextBlock>
        <TextBlock Name="test1" Text="どろっぷだうん" Foreground="Red" FontSize="20" />
    </Grid>
    <Grid>
        <TextBlock Text="{Binding ElementName=test2, Path=Text}" Foreground="Black" FontSize="{Binding ElementName=test2, Path=FontSize}">
            <TextBlock.RenderTransform>
                <transformgroup>
                    <TranslateTransform X="0" Y="1" />
                </transformgroup>
            </TextBlock.RenderTransform>
        </TextBlock>
        <TextBlock Text="{Binding ElementName=test2, Path=Text}" Foreground="Black" FontSize="{Binding ElementName=test2, Path=FontSize}">
            <TextBlock.RenderTransform>
                <TranslateTransform X="0" Y="-1" />
            </TextBlock.RenderTransform>
        </TextBlock>
        <TextBlock Text="{Binding ElementName=test2, Path=Text}" Foreground="Black" FontSize="{Binding ElementName=test2, Path=FontSize}">
            <TextBlock.RenderTransform>
                <TranslateTransform X="1" Y="0" />
            </TextBlock.RenderTransform>
        </TextBlock>
        <TextBlock Text="{Binding ElementName=test2, Path=Text}" Foreground="Black" FontSize="{Binding ElementName=test2, Path=FontSize}">
            <TextBlock.RenderTransform>
                <TranslateTransform X="-1" Y="0" />
            </TextBlock.RenderTransform>
        </TextBlock>
        <TextBlock Name="test2" Text="縁取りてすと" Foreground="Red" FontSize="20" />
    </Grid>
</StackPanel>

 

こちらで紹介している文字の縁取り方法ですが、より綺麗な方法を紹介していますので、そちらも参考にしてください

Categories: WPF, プログラミング

 

WPF – StatusBarItemの右寄せ
WPF – トグル表示可能なボタンの作成

コメントを残す

コメントを投稿するにはログインしてください。

  • 2011年1月
    日 月 火 水 木 金 土
     1
    2345678
    9101112131415
    16171819202122
    23242526272829
    3031  
    « 11月   4月 »
  • 最近の投稿

    • raspberry pi に nginx をセットアップする
    • VSCode を日本語化する
    • raspberry pi に VSCode をインストールする
    • WindowsのプロダクトIDを取得する
    • SQL Server – money型とdecimal型を併用した金額計算
  • アーカイブ

    • 2020年3月
    • 2016年12月
    • 2014年6月
    • 2014年5月
    • 2013年7月
    • 2012年11月
    • 2012年7月
    • 2012年5月
    • 2012年4月
    • 2011年4月
    • 2011年1月
    • 2010年11月
    • 2010年10月
    • 2010年9月
    • 2010年8月
    • 2010年7月
    • 2010年6月
    • 2010年5月
    • 2010年4月
  • カテゴリー

    • C#
    • jQuery
    • OpenCV
    • raspberry pi
    • SharePoint
    • Silverlight
    • SQL Server
    • WCF
    • WPF
    • プログラミング
    • 未分類
    • 雑記
© astel-labs.net. Proudly Powered by WordPress | Nest Theme by YChong

このブログ内で公開されているソースコードおよびサンプルプログラムに関わるライセンスはすべて修正BSDライセンス(New BSD License)として公開しています。
但し、サンプルプログラムに含まれる外部アセンブリが同様のライセンスとは限りませんので、利用する前に必ずすべてのライセンスの確認を行ってください。