首页 > 解决方案 > 在 Xamarin.Forms 中使用 PathGeometry 剪切视图

问题描述

我正在尝试使用以下路径剪辑 StackLayout,但它不会在窗口中剪辑任何内容:GaugeView.xaml:

<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Xamarin.Forms.GaugeView.GaugeView">
    <ContentView.Content>
        <StackLayout
            BackgroundColor="Red"
            HorizontalOptions="FillAndExpand"
            VerticalOptions="FillAndExpand">
            <StackLayout.Clip>
                <PathGeometry
                    Figures="M0,150A300,300 0 1,1 300,150L220,150A300,300 0 1,1 80,150Z"/>
            </StackLayout.Clip>
            <Label
                Text="Hello clip"/>

        </StackLayout>
    </ContentView.Content>
</ContentView>

MainPage.xaml:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Xamarin.Forms.GaugeView.MainPage"
             xmlns:local="clr-namespace:Xamarin.Forms.GaugeView">

    <StackLayout>
        <StackLayout>
            <local:GaugeView
                    HorizontalOptions="Center"
                    WidthRequest="100"
                    HeightRequest="100"/>
        </StackLayout>
    </StackLayout>

</ContentPage>

什么都不剪辑

我做错了什么?

标签: xamarin.forms

解决方案


推荐阅读