我是 Xamarin Forms 的新手,我来自 WPF 背景。在 WPF 中,很容易将背景图像(远程)设置为形状。 Xamarin Forms 中是否有任何等效的东西?
最佳答案
在将 Shapes 和 Paths 引入 Xamarin.Forms 之后,您可以在 Grid 中实现它:
<Grid HorizontalOptions="Center" VerticalOptions="Center">
<Ellipse Stroke="blue" StrokeThickness="5" Fill="Black" Aspect="Fill"/>
<Image Source="xamarin.png" WidthRequest="300" HeightRequest="300"/>
</Grid>
带
Frame
的圆角:<Grid HorizontalOptions="Center" VerticalOptions="Center">
<Frame WidthRequest="200" CornerRadius="80"
BackgroundColor="Black" HeightRequest="200"/>
<Image Source="xamarin.png" WidthRequest="200" HeightRequest="200"/>
</Grid>
使用
Path
:<Grid HorizontalOptions="Center" VerticalOptions="Center">
<Path Stroke="blue"
Data="m123.87668,219.80811l21.30223,-42.92685l36.89384,-24.78565l42.60447,0l36.89384,24.78565l21.30223,42.92685l0,49.57131l-21.30223,42.92685l-36.89384,24.78564l-42.60447,0l-36.89384,-24.78564l-21.30223,-42.92685l0,-49.57131z"
StrokeThickness="5" WidthRequest="200" HeightRequest="200"
Aspect="Fill" Fill="Black"/>
<Image Source="xamarin.png" WidthRequest="200" HeightRequest="200"/>
</Grid>
相关文档
关于xaml - 如何将背景图像设置为形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50958787/