我需要为我的应用程序创建一个图像按钮,例如面向网络的风格。
我有一个 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>
怎么了?
SOLUTION
我发现最好的解决方案是:
<Image Source="/MyNamespace;component/images/star_yellow.png" ManipulationStarted="Image_ManipulationStarted" Width="20" Height="20"></Image>
谢谢大家!
我没有在您的代码中看到特定的错误,但我现在没有工具来测试它并查看它失败的原因。
但是,您可以使用图像创建 VisualBrush 并将其用作按钮的背景:
<Button>
<Button.Background>
<ImageBrush ImageSource="xyz.png"/>
</Button.Background>
</Button>
大多数背景都是 Brush 类型,因此您可以使用 SolidColorBrush、LinearGradientBrush、ImageBrush 等。您不受颜色限制。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)