图像填充在WPF按钮空间 [英] Image fill the space on the button in WPF

查看:126
本文介绍了图像填充在WPF按钮空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按钮在我的WPF应用程序,我希望有一个图片来填补按钮完全。目前,我有以下code,它不填写按钮

I have Button on my WPF app and I want an Image to fill the Button completely. Currently I have The following code and it does not fill the 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>

我是否需要调整图片 WPF外面然后使用它?请帮助。

Do I need resize the Image outside WPF then Use it? Please help.

推荐答案

您可以尝试改变你的图片的ImageBrush 键,然后分配给你的背景那么你的图像将伸展你的按钮内表面上。

You can try changing your Image to an ImageBrush and then assign that to your BackGround your image will then stretch over the inner surface of your button.

<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添加到您的按钮内容和图像分配为背景的。

or add a TextBlock to your Button Content and assign your Image as a BackGround to it.

<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>

这篇关于图像填充在WPF按钮空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆