创建圆形图像Xaml

Ano*_*eek 6 xaml windows-phone-8

在Windows Phone 8中,我想将图像放在一个圆圈中.是否有一个像网格一样的圆形容器?我知道有椭圆位,它不是一个容器

sig*_*ger 11

我就是这样做的.

<Ellipse Width="100"
         Height="100">
    <Ellipse.Fill>
        <ImageBrush>
            <ImageBrush.ImageSource>
                <BitmapImage UriSource="/YourImage.png" />
            </ImageBrush.ImageSource>
        </ImageBrush>
    </Ellipse.Fill>
</Ellipse>
Run Code Online (Sandbox Code Playgroud)

作为最佳实践,请考虑设置DecodePixelWidthDecodePixelHeight与椭圆相同的大小.


Chr*_* W. 7

mleroy的答案的另一个选择(因为如果我记得正确的WP是基于silverlight而且我经常遇到缺乏刷子可用性来做这样的事情.)你可以使用该Clip属性来做到这一点.

例如;

<Image 
  Source="blah\yourpicture.jpg" 
  Width="100" Height="100">
  <Image.Clip>
    <EllipseGeometry
      RadiusX="100"
      RadiusY="100"
      Center="100,100"/>
  </Image.Clip>
</Image>
Run Code Online (Sandbox Code Playgroud)

希望这会有所帮助,欢呼

编辑添加:您还可以将半径X/Y绑定到图像的宽度/高度,以便在动态大小的图像上获得更大的灵活性.

  • 注意,EllipseGeometry 在 Windows 10 通用应用程序中不可用。 (2认同)