我需要为我的应用程序创建一个图像按钮,如面向web的样式。
我有一个20×20像素的图像,并且想要具有与图像相同尺寸的图像按钮。
我有一个20×20像素的图像,并且想要具有与图像相同尺寸的图像按钮。
我试图将它设置在我的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>
哪里不对?
解
我发现最好的解决办法是:
<Image Source="/MyNamespace;component/images/star_yellow.png" ManipulationStarted="Image_ManipulationStarted" Width="20" Height="20"></Image>
谢谢大家!
我的代码中没有看到特定的错误,但是现在我没有工具来测试它,看看它为什么失败。
但是,您可以使用您的图像创建一个VisualBrush,并将其用作Button的背景:
<Button>
<Button.Background>
<ImageBrush ImageSource="xyz.png"/>
</Button.Background>
</Button>
大多数背景是Brush类型,所以您可以使用SolidColorBrush,LinearGradientBrush,ImageBrush等。您不限于颜色。