I have Button
在我的 WPF 应用程序上,我想要一个Image
来填补Button
完全地。目前我有以下代码,它没有填充Button
.
<Image x:Key="MyResource" Source="Images/up-arrow-icon.jpg" Margin="0" />
<telerik:RadButton Height="25" Width="40" HorizontalAlignment="Left" Margin="417,10,0,0"
Name="radButton1" VerticalAlignment="Top" Click="UpButtonClick">
<telerik:RadButton.Content>
<StaticResource ResourceKey="MyResource"/>
</telerik:RadButton.Content>
</telerik:RadButton>
我需要调整大小吗Image
那么在WPF之外使用它吗?
你可以尝试改变你的Image
to an ImageBrush
然后将其分配给您的BackGround
然后您的图像将拉伸到按钮的内表面。
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<ImageBrush x:Key="MyResource" ImageSource="C:\temp\test.jpg" />
</Window.Resources>
<Grid>
<Button Height="25" Background="{StaticResource MyResource}" Width="40" HorizontalAlignment="Left" Margin="417,10,0,0" VerticalAlignment="Top"/>
</Grid>
</Window>
或者将 TextBlock 添加到按钮内容并将图像指定为背景。
<Window.Resources>
<ImageBrush x:Key="MyResource" ImageSource="C:\temp\test.jpg" />
</Window.Resources>
<Grid>
<Button Height="25" Width="40" HorizontalAlignment="Left" Margin="417,10,0,0" VerticalAlignment="Top">
<Button.Content>
<TextBlock HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="34" Height="19" Margin="0">
<TextBlock.Background>
<StaticResource ResourceKey="MyResource"/>
</TextBlock.Background>
</TextBlock>
</Button.Content>
</Button>
</Grid>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)