本文介绍了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:关键词]
发布评论