【问题标题】:How to draw paths in Xamarin.Forms XAML如何在 Xamarin.Forms XAML 中绘制路径
【发布时间】:2017-11-23 04:00:26
【问题描述】:

来自 Windows Phone Silverlight、WPF 和 UWP 世界,我现在正在研究 Xamarin.Forms 以将应用程序移植到 iOS 和 Android。到目前为止,该应用程序的所有图标和徽标都是 Path 文件中的 App.xaml 元素。例如:

<DataTemplate x:Key="ImageAdd">
    <Path Width="30" 
     Height="30" 
     Stretch="Fill" 
     Fill="{StaticResource TsColorWhite}" 
     Data="F1 M 35,19L 41,19L 41,35L 57,35L 57,41L 41,41L 41,57L 35,57L 35,41L 19,41L 19,35L 35,35L 35,19 Z "/>
</DataTemplate>

有了这个,应用程序不需要为不同的屏幕分辨率缩放图形。

Path 位于 System.Windows.Shapes 命名空间中,因此在 XF 中不可用。

所以问题是:如何在 Xamarin.Forms 中加载和显示此类路径?

【问题讨论】:

  • 在 Windows 上运行原始应用程序并截取徽标。另存为 .PNG

标签: c# xaml xamarin.forms


【解决方案1】:

从 Xamarin.Forms 4.7.0 开始引入 Shapes,您可以直接在 xaml 中绘制路径。 Aspect 属性等效于 Xamarin.Forms 中的 Stretch 属性。形状(包括路径)位于 Xamarin.Forms.Shapes 命名空间中。

<DataTemplate x:Key="ImageAdd">
    <Path Width="30"
          Height="30"
          Aspect="Fill"
          Fill="{StaticResource TsColorWhite}"
          Data="F1 M 35,19L 41,19L 41,35L 57,35L 57,41L 41,41L 41,57L 35,57L 35,41L 19,41L 19,35L 35,35L 35,19 Z "/>
</DataTemplate>

相关文档

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多