在 ContentView 添加的 GraphicView 可以在 android 中显示而不能在 Windows 中显示,这是一个 bug 吗

Leon Lu (Shanghai Wicresoft Co,.Ltd.) 68,901 信誉分 Microsoft 供应商
2024-04-12T05:42:52.0133333+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>

在 contentview 中添加 graphicview,然后在 contentpage 中添加 contentview,在 android上 可以正常运行,但在 windows 上不显示 graphicview.

如果在 ContentPage 添加 GraphicView,则在两个平台上都可以正确显示。

为什么? 这是一个 Bug 吗?

提前致谢 此问题整理于:ContentView add GraphicView can display in android and not display in windows ? bug?

.NET MAUI
.NET MAUI
一种 Microsoft 开源框架,用于构建跨移动设备、平板电脑、台式机的原生设备应用程序。
43 个问题
0 个注释 无注释
{count} 票

接受的答案
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 36,231 信誉分 Microsoft 供应商
    2024-04-12T05:44:13.6133333+00:00

    你好,

    我用以下 Drawable 重现了您的问题,出现此问题的原因是在 ContentView 中,如果不设置最小宽度和高度,则在 Windows 中其默认大小为 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);
        }
    }
    

    因此,您可以为 GraphicsView 设置 MinimumHeightRequest 和 MinimumWidthRequest 属性的初始值来解决此问题。

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

    如果答案是正确的,请点击“接受答案”并点赞。 如果您对此答案还有其他疑问,请点击“评论”。 注意:如果您想接收相关电子邮件,请按照我们的文档中的步骤启用电子邮件通知 此线程的通知。

    0 个注释 无注释

0 个其他答案

排序依据: 非常有帮助