xaml - 如何将背景图像设置为形状

标签 xaml xamarin.forms background-image

我是 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>
enter image description here

Frame 的圆角:
<Grid HorizontalOptions="Center" VerticalOptions="Center">
    <Frame WidthRequest="200" CornerRadius="80"
           BackgroundColor="Black" HeightRequest="200"/>
    <Image Source="xamarin.png" WidthRequest="200" HeightRequest="200"/>
</Grid>
enter image description here

使用 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>
enter image description here

相关文档
  • 微软博客:Drawing UI with Xamarin.Forms Shapes and Paths .
  • 微软官方文档:Xamarin.Forms Shapes .
  • GitHub:规范:Shapes & Paths
  • 关于xaml - 如何将背景图像设置为形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50958787/

    相关文章:

    css - Firefox 中的渐进式 JPG 背景图像问题

    html - 如何使 html 中的图像变暗(不是 css)

    javascript - 使用 Jquery 或 Javascript 在 HTML 中获取 div 背景图像的尺寸

    c# - 为什么C#不像VB那样有Handles子句?

    c# - 具有任意列和行的 Wpf DataGrid 数据绑定(bind)

    c# - 如何将带有 <Grid> 的 <ViewCell> 添加到 C# 中的 TableView

    c# - James Montemagno 的 Xam.Plugins.Settings 似乎没有保存我的设置

    c# - 类似于 jQuery UI 的模态对话框

    c# - 以编程方式寻址在 xaml 中创建的 Canvas

    c# - 无法选择 ListView 项目两次