c# - Windows 运行时 : How to set image in a ellipse shape button?

标签 c# windows-runtime winrt-xaml

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

相关文章:

c# - azure 上的 FFMpeg 函数无法处理同时调用(超过 5 个)

c# - 在 DataGridView 中选择一行并跟随行标题上的箭头

C# 在当前 ListView 中拖放 move 项目

c# - RGiesecke dll 导出模板

c++ - auto foo = ref new Foo();什么是 "ref"?

https - HttpClient->GetStringAsync() 对于 https Uris 抛出 0x000006F4

c# - 如何播放需要认证的视频流?

c# - WP 8.1 RT 的大图 block 变灰;较小的瓷砖看起来很好

c# - 如何检查 OnNavigatedTo 是否由 Windows Phone 8.1 通用应用程序中的后退按钮触发?

winrt-xaml - 如何将UserControl中的所有文本框添加到GridView中