JulieC
JulieC

Reputation: 193

WPF Button Image not showing up

I have a small sandbox program. I cannot get the image on a button to appear at runtime. I can see it fine at design time. I've checked the properties, I stripped the XAML down to the bare minimum and it just doesn't show up. The button is "there", I get to the Click handler if I click in the area.

The Build Action of the .png file is Resource.

<Window x:Class="WpfSandbox.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">

<Window.Resources>
    <ControlTemplate x:Key="SpinnerButton" TargetType="{x:Type Button}">
        <Grid>
            <Image
                x:Name="SpinnerButtonImage"
                Height="80"
                Width="80"
                Margin="0,0,0,0"
                Visibility="Visible"
                Source="pack://application:,,,/Resources/spinner.png">
            </Image>
            <TextBlock>Yo!</TextBlock>
        </Grid>
    </ControlTemplate>
</Window.Resources>

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="298*"/>
        <ColumnDefinition Width="219*"/>
    </Grid.ColumnDefinitions>
    <Button Template="{DynamicResource SpinnerButton}" Height="100" Width="100" Click="OnSpinnerClick" Margin="100,100,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" />
</Grid>
</Window>

Upvotes: 1

Views: 2190

Answers (1)

Panh
Panh

Reputation: 225

Remove the height and width of the image and allow it to resize on its own within the button. This should allow it to take up the full area it's provided by the button and always show up.

Upvotes: 2

Related Questions