.NET MAUI
一种 Microsoft 开源框架,用于构建跨移动设备、平板电脑、台式机的原生设备应用程序。
43 个问题
<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?
你好,
我用以下 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}"/>
如果答案是正确的,请点击“接受答案”并点赞。 如果您对此答案还有其他疑问,请点击“评论”。 注意:如果您想接收相关电子邮件,请按照我们的文档中的步骤启用电子邮件通知 此线程的通知。