带有背景色和图像的 WPF 椭圆
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13177529/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF Ellipse with BackgroundColor and Image
提问by Armando Freire
I'm developing a Windows Phone application and I have some Ellipses. Is it possible to have a background image on them AND a background color?
我正在开发一个 Windows Phone 应用程序,我有一些椭圆。是否可以在它们上面添加背景图像和背景颜色?
When I looked for it, VS only allows me to change the Fill property with an image but didn't allow me to keep the Color on Fill + the Image.
当我寻找它时,VS 只允许我使用图像更改填充属性,但不允许我将颜色保留在填充 + 图像上。
回答by Wonko the Sane
Just use two ellipses, overlapping each other:
只需使用两个相互重叠的椭圆:
<Grid>
<Ellipse Width="100" Height="60" Fill="Navy" />
<Ellipse Width="100" Height="60">
<Ellipse.Fill>
<RadialGradientBrush>
<GradientStop Color="#00FF0000" Offset="0" />
<GradientStop Color="#FFFF0000" Offset="1" />
</RadialGradientBrush>
</Ellipse.Fill>
</Ellipse>
</Grid>
Change the fill property of the second to use your image.
更改第二个的填充属性以使用您的图像。
回答by Anonymous
try this:
尝试这个:
<Ellipse>
<Ellipse.Fill>
<ImageBrush ImageSource="/myimage.png" Stretch="Fill"></ImageBrush>
</Ellipse.Fill>
</Ellipse>

