admin管理员组

文章数量:1278988

Controls -> Views -> Shapes -> Paths -> Path class is not working properly though I have written correct code:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns=";
             xmlns:x=";
             x:Class="_23_Path.MainPage"
             Title="MainPage">


    <ScrollView>
        <StackLayout>
            <!-- Example 1-->
            <Label Text="Example 1" />
            <Path Stroke="Black" Aspect="Uniform" HorizontalOptions="Start">
                <Path.Data>
                    <PathGeometry>
                        <PathGeometry.Figures>
                            <PathFigureCollection>
                                <PathFigure IsClosed="True"
                                StartPoint="10,100">
                                    <PathFigure.Segments>
                                        <PathSegmentCollection>
                                            <LineSegment Point="100,100" />
                                            <LineSegment Point="100,50" />
                                        </PathSegmentCollection>
                                    </PathFigure.Segments>
                                </PathFigure>
                            </PathFigureCollection>
                        </PathGeometry.Figures>
                    </PathGeometry>
                </Path.Data>
            </Path>
        </StackLayout>
    </ScrollView>

</ContentPage>

See this code, after running in the android simulation it is not showing the drawing!

Expecting a output of the path image.

Controls -> Views -> Shapes -> Paths -> Path class is not working properly though I have written correct code:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft/winfx/2009/xaml"
             x:Class="_23_Path.MainPage"
             Title="MainPage">


    <ScrollView>
        <StackLayout>
            <!-- Example 1-->
            <Label Text="Example 1" />
            <Path Stroke="Black" Aspect="Uniform" HorizontalOptions="Start">
                <Path.Data>
                    <PathGeometry>
                        <PathGeometry.Figures>
                            <PathFigureCollection>
                                <PathFigure IsClosed="True"
                                StartPoint="10,100">
                                    <PathFigure.Segments>
                                        <PathSegmentCollection>
                                            <LineSegment Point="100,100" />
                                            <LineSegment Point="100,50" />
                                        </PathSegmentCollection>
                                    </PathFigure.Segments>
                                </PathFigure>
                            </PathFigureCollection>
                        </PathGeometry.Figures>
                    </PathGeometry>
                </Path.Data>
            </Path>
        </StackLayout>
    </ScrollView>

</ContentPage>

See this code, after running in the android simulation it is not showing the drawing!

Expecting a output of the path image.

Share Improve this question edited Feb 24 at 10:43 marc_s 755k184 gold badges1.4k silver badges1.5k bronze badges asked Feb 24 at 10:02 S MajumderS Majumder 11 bronze badge 0
Add a comment  | 

2 Answers 2

Reset to default 0

I see that your example is following the documentation on https://learn.microsoft/en-us/dotnet/maui/user-interface/controls/shapes/path?view=net-maui-9.0 - I have used the Path syntax extensively and you can see several of my StackOverflow posts based on Path. I would recommend trying these things:

  • Ensuring that the Path has a defined Width and Height (e.g. set WidthRequest and HeightRequest, or put it in a Grid where the Grid dimensions are set)
  • Try a different color, e.g. Red, to avoid the possibility of drawing Black on Black.

Here are some of my StackOverflow posts: https://stackoverflow/search?q=user%3A881441+path+%5Bmaui%5D

I have found the issue, if we remove the property 'HorizontalOptions="Start" ' from the Path class the image is showing! Somebody try this code, and let me know is it working on your system or not with .NET9 and .NET 8 also.

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft/winfx/2009/xaml"
             x:Class="_23_Path.MainPage">


    <ScrollView>
        <Path Data="M 10, 100 L 100, 100 100, 50Z" Stroke="Black" Aspect="Uniform" />
    </ScrollView>

</ContentPage>

本文标签: cPath is not working in NET MAUI with NET 9Stack Overflow