<Window x:Class="ButtonSample.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <DockPanel LastChildFill="False"> <StackPanel DockPanel.Dock="Top"> <!--普通のボタンを表示--> <Button> くるっく〜♪ </Button> <!--ボタンの中に画像を表示--> <Button> <Image Height="20" Source="windows.png"/> </Button> <!--ボタンの中に画像とテキストを表示--> <Button> <DockPanel LastChildFill="True"> <Image Height="20" Source="windows.png" DockPanel.Dock="Left"/> <TextBlock Text="くるっく〜♪"/> </DockPanel> </Button> </StackPanel> <!--ツールバーに載せてみる--> <ToolBar DockPanel.Dock="Top"> <!--画像の右にテキストを表示--> <Button> <DockPanel LastChildFill="True"> <Image Height="20" Source="windows.png" DockPanel.Dock="Left"/> <TextBlock Text="くるっく〜♪"/> </DockPanel> </Button> <!--画像の下にテキストを表示--> <Button> <DockPanel LastChildFill="True"> <Image Height="20" Source="windows.png" DockPanel.Dock="Top"/> <TextBlock Text="くるっく〜♪"/> </DockPanel> </Button> </ToolBar> </DockPanel> </Window>
要素の合成ができるので、通常のボタンに画像を表示するのは簡単。でもツールバーボタンに画像とテキストを表示するのは、WinForm の ToolStripButton に比べてちょっと面倒(難しくはないけど)。
「画像を表示できる Button」みたいなカスタムコントロールを作るべきなんだろうか。