<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 >
我有一个椭圆形的按钮,默认情况下有颜色填充。 我想在运行时的代码隐藏中将填充更改为图像。
我该怎么做?
更多信息: 我尝试使用“ellipsePicture”名称设置椭圆填充,但在后面的代码中无法引用此名称,但我不知道原因。
最佳答案
试试下面的代码..
<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 >
在您的代码后面添加以下行..
BtnProfilePicture.BackgroundImage =
new ImageBrush { ImageSource = LoadBackgroundImage(yourfilename.jpg)};
如果可行,请投票给我!
关于c# - Windows 运行时 : How to set image in a ellipse shape button?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31113614/