简体   繁体   中英

Image filling a button WP8 Xaml

I have the following image within a button, As you can see from the screenshot though the button is larger than the image. If I try to reduce the size of the button the image is reduced aswell. How do make the image fill the button with no blanks?

在此处输入图片说明

This is my xaml code

    <Button x:Name="Settings" Margin="344,161,0,268" Background="Transparent" BorderThickness="0" Click="Settings_Click">
        <Image Source="Assets/wrench.jpg" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" Width="74.487" d:LayoutRounding="Auto">
            <Image.RenderTransform>
                <CompositeTransform Rotation="0.63"/>
            </Image.RenderTransform>
        </Image>
    </Button> 

----EDIT My new code as per your suggestions is this, i removed the rotation aswell as it was set by mistake, it is closer now to the full button but not yet

    <Button x:Name="Settings" Padding="0" Margin="344,161,0,273" Background="Transparent" BorderThickness="0" Click="Settings_Click">
        <Image Source="Assets/wrench.jpg" Stretch="Fill" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="True" d:LayoutRounding="Auto">
        </Image>
    </Button>

You need to:

  • set your Image width and height properties
  • add Stretch="Fill" to your Image
  • remove default padding from Padding (set to 0)

Other solution is to add Tap event to event and remove button.

If you want to handle Tap instead of Click you must get to know that second parameter in Click event handler is type of RoutedEventArgs , and in Tap event handler is type of GestureEventArgs .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM