Windows 运行时:如何在椭圆形按钮中设置图像?

编程入门 行业动态 更新时间:2024-10-15 04:19:25
本文介绍了Windows 运行时:如何在椭圆形按钮中设置图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..
<Button x:Name="btnProfilePicture" HorizontalAlignment="Center" Click="btnProfilePicture_Click">
    <Button.Template>
        <ControlTemplate>
            <Ellipse x:Name="ellipsePicture" Fill="Turquoise" Width="150" Height="150" Stroke="White" StrokeThickness="10">
            </Ellipse>
        </ControlTemplate>
    </Button.Template>
</Button >

我有一个椭圆形按钮,默认为颜色填充.我想在运行时在代码隐藏中将填充更改为图像.

I have a button in ellipse shape, with color fill by default. I want to change the fill to an image in code-behind in runtime.

我该怎么做?

更多信息:我尝试使用ellipsePicture"名称设置椭圆填充,但后面的代码中无法引用此名称,但我不知道原因.

More info: I tried to set the ellipse fill by using the "ellipsePicture" name but this name cannot be referenced in the code behind but I dont know the reason.

推荐答案

试试下面的代码..

<Button x:Name="BtnProfilePicture" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10">
            <Button.Template>
                <ControlTemplate>
                    <Grid Height="100">
                        <Ellipse x:Name="ellipsePicture" Fill="{TemplateBinding Background}"/>
                    </Grid>
                </ControlTemplate>
            </Button.Template>
        </Button >

在后面的代码中添加以下行..

On your code behind add the following line..

BtnProfilePicture.BackgroundImage = 
           new ImageBrush { ImageSource = LoadBackgroundImage(yourfilename.jpg)};

如果这行得通,请投票给我!

Vote me if this works!

这篇关于Windows 运行时:如何在椭圆形按钮中设置图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-25 13:09:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1116649.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按钮   图像   如何在   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!