WPF Button with Image

wpf
wonea picture wonea · Apr 23, 2010 · Viewed 198.5k times · Source

I'm trying to attach an image on a button in WPF, however this code fails. Seems strange after similar code would work perfectly in Mozilla XUL.

<Button Height="49.086" Margin="3.636,12,231.795,0" Name="button2" 
        VerticalAlignment="Top" Grid.Column="1" Click="button2_Click" 
        Source="Pictures/apple.jpg">Disconnect from Server</Button>

Answer

wpfwannabe picture wpfwannabe · Apr 23, 2010

You want to do something like this instead:

<Button>
    <StackPanel>
        <Image Source="Pictures/apple.jpg" />
        <TextBlock>Disconnect from Server</TextBlock>
    </StackPanel>
</Button>