Image filling a button UWP Xaml

15,666

You probably need to change the Padding and BorderThickness properties of the button. As code below :

    <Button Grid.Column="0" Height="39" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Padding="0" BorderThickness="0">
        <Image Source="Assets/microsoft.png" Stretch="UniformToFill"/>
    </Button>
Share:
15,666
user3821206
Author by

user3821206

Updated on July 23, 2022

Comments

  • user3821206
    user3821206 almost 2 years

    I am having problem in stretching my image to fill the button,I am new in UWP this is my code:

     <Grid  Margin="0,0,0,54" VerticalAlignment="Bottom" Height="39" Style="{Binding HorizontalAlignment, ElementName=grid}" ScrollViewer.HorizontalScrollBarVisibility="Auto">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
    
            <Button Grid.Column="0"  Height="39" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
                <Image Source="images/icon1.png" Stretch="Fill" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="True" d:LayoutRounding="Auto" />
    
            </Button>
            <Button Grid.Column="1"  Height="39" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
                <Image Source="images/icon2.png" Stretch="Fill" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="True" d:LayoutRounding="Auto" />
            </Button>
    
    </Grid>
    
  • Hong
    Hong almost 6 years
    Source="/Assets/microsoft.png" will work even if the Xaml file is not in the root folder.