[英]Unable to access Xamarin.Forms.Shapes Namespace and API in Code behind
我正在嘗試使用 Xamarin.Forms 此處顯示的形狀實驗功能創建動態形狀,盡管它在 xaml 中工作,但我需要使用實驗標志動態創建路徑和形狀。
Xamarin 文檔僅顯示 xaml 示例,並且沒有 API 或在代碼后面使用Shapes
和Path
的參考。
這是我的 Xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="SpotlightTest.MainPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<AbsoluteLayout>
<StackLayout
Margin="0"
AbsoluteLayout.LayoutBounds="0,0,1,1"
AbsoluteLayout.LayoutFlags="All"
BackgroundColor="Orange"
Spacing="0">
<!-- Place new controls here -->
<Button
BackgroundColor="Yellow"
BorderColor="Red"
BorderWidth="2"
CornerRadius="50"
HeightRequest="100"
HorizontalOptions="Start"
Text="Explore"
WidthRequest="100" />
<Label
HorizontalOptions="Center"
Text="Welcome to Xamarin.Forms!"
VerticalOptions="CenterAndExpand" />
</StackLayout>
<Grid
x:Name="ShadowContainer"
Padding="0"
AbsoluteLayout.LayoutBounds="0,0,1,1"
AbsoluteLayout.LayoutFlags="All"
BackgroundColor="Transparent">
<Path
x:Name="MyPath"
Fill="#66000000"
Stroke="Red"
StrokeThickness="1">
<Path.Data>
<GeometryGroup>
<EllipseGeometry
Center="55,55"
RadiusX="55"
RadiusY="55" />
<RectangleGeometry Rect="00,00,400,700" />
</GeometryGroup>
</Path.Data>
</Path>
</Grid>
</AbsoluteLayout>
</ContentPage>
I have tried to use Shapes
and Path
even added Xamarin.Forms.Shapes
namespace but i am not able to access the API seems like it is not present in the .dll
but it worked fine in xaml page, how can i access it in code在后面? 我正在使用 Xamarin.Forms 4.8.0.1687
首先,您應該在App.xaml.cs
中設置Shapes_Experimental
標志
public App()
{
Device.SetFlags(new[] { "Shapes_Experimental", "Brush_Experimental" });
InitializeComponent();
MainPage = new MainPage();
}
然后您可以在 xaml.cs 后面的代碼中訪問它:
using Xamarin.Forms.Shapes;
Path path = new Path();
path.Fill = new SolidColorBrush(Color.FromHex("#66000000"));
path.Stroke = Brush.Red;
path.StrokeThickness = 1;
GeometryGroup geometryGroup = new GeometryGroup();
geometryGroup.Children.Add(new EllipseGeometry() { Center = new Point(55, 55), RadiusX = 55, RadiusY = 55 });
geometryGroup.Children.Add(new RectangleGeometry() { Rect = new Rect(00,00,400,700) });
path.Data = geometryGroup;
ShadowContainer.Children.Add(path);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.