ContentView add GraphicView can display in android and not display in windows ? bug?

Fei Xu 490 Reputation points
2023-03-14T15:48:50.56+00:00
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:drawables="clr-namespace:myMolly.Drawables"
             x:Class="myMolly.Controls.JPScoreView">
    <ContentView.Resources>
        <drawables:JPScoreDrawable x:Key="drawable" />
    </ContentView.Resources>
    <VerticalStackLayout x:Name="vStackLayout">
        <Label Text="ABCD" HorizontalOptions="Center"/>
        <GraphicsView x:Name="gViewPart" HorizontalOptions="Center" Drawable="{StaticResource drawable}"/>
        <Grid x:Name="gridViews"></Grid>
    </VerticalStackLayout>
</ContentView>

graphicview added in contentview,and contentview added in contentpage, that can run correct on android but not display on windows

if graphicview added in contentpage, it can be correct on both

why? bug?
Developer technologies | .NET | .NET MAUI
{count} votes

Answer accepted by question author
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,151 Reputation points Microsoft External Staff
    2023-03-15T03:00:42.16+00:00

    Hello,

    I reproduced your problem with the following Drawable, and the reason for this problem is that in ContentView, if you don't set the minimum width and height, in Windows its size is 0.

    public class GraphicsDrawable : IDrawable
    {
        public void Draw(ICanvas canvas, RectF dirtyRect)
        {
            LinearGradientPaint linearGradientPaint = new LinearGradientPaint
            {
                StartColor = Colors.Yellow,
                EndColor = Colors.Green,
                // StartPoint is already (0,0)
                EndPoint = new Point(1, 0)
            };
    
           RectF linearRectangle = new RectF(10, 10, 200, 100);
            canvas.SetFillPaint(linearGradientPaint, linearRectangle);
            canvas.SetShadow(new SizeF(10, 10), 10, Colors.Grey);
            canvas.FillRoundedRectangle(linearRectangle, 12);
        }
    }
    

    Therefore, you could set MinimumHeightRequest and MinimumWidthRequest to GraphicsView to solve this problem.

    <GraphicsView MinimumHeightRequest="300" MinimumWidthRequest="300" x:Name="gViewPart" HorizontalOptions="Center" Drawable="{StaticResource drawable}"/>
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.