简体   繁体   English

图像填充按钮WP8 Xaml

[英]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 这是我的XAML代码

    <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 ---- EDIT根据您的建议,我的新代码是这个,我删除了旋转以及错误设置的旋转,现在它更接近完整按钮了,但是还没有

    <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 将Stretch =“ Fill”添加到您的图像
  • remove default padding from Padding (set to 0) 从填充中删除默认填充(设置为0)

Other solution is to add Tap event to event and remove button. 其他解决方案是将Tap事件添加到事件并删除按钮。

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 . 如果要处理Tap而不是Click,则必须知道Click事件处理程序中的第二个参数是RoutedEventArgs类型,而Tap事件处理程序中的第二个参数是GestureEventArgs类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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