#361 – Creating a ToggleButton Whose Content Is an Image
August 10, 2011 1 Comment
Because ToggleButton is a ContentControl, it can contain a single child element that can be any .NET object. You typically set the ToggleButton’s content to a text string, which appears as a label on the button. But you can also set the content to some other control.
In the example below, the content of each ToggleButton in a panel is set to an Image control.
<StackPanel HorizontalAlignment="Center" Margin="15">
<Label Content="Click on cartoon characters that you like:"/>
<StackPanel>
<ToggleButton HorizontalAlignment="Center" Margin="5" Padding="5">
<Image Source="001-Bugs.jpg" Stretch="None"/>
</ToggleButton>
<ToggleButton HorizontalAlignment="Center" Margin="5" Padding="5">
<Image Source="002-Underdog.jpg" Stretch="None"/>
</ToggleButton>
<ToggleButton HorizontalAlignment="Center" Margin="5" Padding="5">
<Image Source="003-Betty.jpg" Stretch="None"/>
</ToggleButton>
<ToggleButton HorizontalAlignment="Center" Margin="5" Padding="5">
<Image Source="004-Bart.jpg" Stretch="None"/>
</ToggleButton>
</StackPanel>
</StackPanel>
