Windows Phone 7图像按钮

Nic*_*nto 16 imagebutton windows-phone-7

我需要为我的应用程序创建一个图像按钮,如面向Web的样式.我有一个20x20像素的图像,并希望图像按钮具有相同的图像尺寸.

我试图在我的xaml中设置它但它不起作用:

<Button Grid.Row="0" Margin="0" Padding="0" Click="AddtoFavorite_Click" Width="20" Height="20"  VerticalAlignment="Top" HorizontalAlignment="Right">
   <Button.Content>
      <Image Source="/MyNamespace;component/images/star_yellow.png" Margin="0" Width="20" Height="20" />
   </Button.Content>
</Button>
Run Code Online (Sandbox Code Playgroud)

怎么了?


我发现最好的解决方案是:

<Image Source="/MyNamespace;component/images/star_yellow.png" ManipulationStarted="Image_ManipulationStarted" Width="20" Height="20"></Image> 
Run Code Online (Sandbox Code Playgroud)

谢谢大家!

Fra*_*ori 20

我没有在你的代码中看到特别的错误,但我现在没有工具来测试它,看看它失败的原因.

但是,您可以使用图像创建VisualBrush并将其用作Button的背景:

<Button>
    <Button.Background>
        <ImageBrush ImageSource="xyz.png"/>
    </Button.Background>
</Button>
Run Code Online (Sandbox Code Playgroud)

大多数背景都是Brush类型,因此您可以使用SolidColorBrush,LinearGradientBrush,ImageBrush等.您不仅限于颜色.


Mic*_*k N 0

您可以将图像设置为按钮的背景,或者如果您想将其作为内容,理论上它应该在堆栈面板内工作。