使用 MAUI 社区工具包 (MCT) 弹出窗口中的
CarouselView
,轮播数据模板中设置的标签似乎溢出。设置小于弹出窗口宽度的固定 WidthRequest
确实适用于标签区域。然而,文字仍然溢出。看起来,溢出仅发生在标签的右侧。标签区域的宽度似乎正确,但其中的文本要宽得多。
没什么特别的,只是一个带有项目的轮播视图:
<tk:Popup xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:m="clr-namespace:CarouselPopupTest.Models"
xmlns:tk="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
x:Class="CarouselPopupTest.Controls.Popup_Instructions">
<Frame>
<VerticalStackLayout>
<CarouselView ItemsSource="{Binding Global.Instructions}"
IndicatorView="indicatorView"
IsSwipeEnabled="True"
Margin="0,0,0,16"
Loop="False">
<CarouselView.ItemTemplate>
<DataTemplate x:DataType="m:Instruct">
<Frame>
<VerticalStackLayout>
<Label Text="{Binding Title}"
HorizontalTextAlignment="Center"
HorizontalOptions="Center"
WidthRequest="224"/>
<Image Source="{Binding Image}"
WidthRequest="224"/>
<Label Text="{Binding Description}"
HorizontalTextAlignment="Center"
HorizontalOptions="Center"
WidthRequest="224"/>
</VerticalStackLayout>
</Frame>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
<IndicatorView MaximumVisible="8"
x:Name="indicatorView"
HorizontalOptions="End">
<IndicatorView.IndicatorTemplate>
<DataTemplate>
<BoxView Style="{StaticResource IndicatorViewIndicator}"/>
</DataTemplate>
</IndicatorView.IndicatorTemplate>
</IndicatorView>
<Grid ColumnDefinitions="*,*">
<Button ImageSource="btn_check.svg"
Grid.Column="0"/>
</Grid>
</VerticalStackLayout>
</Frame>
</tk:Popup>
以下是在任何设备上调试时查看弹出轮播时的显示方式:
注意:此屏幕截图是在删除
<Image>
后制作的。
图像视图实际上渲染得很好。只有标签元素由于某种未知原因而不断溢出。这是一个错误还是我做了一些我不应该在这里做的事情?
我在.NET7 中重现了这个问题。仅在第一次渲染时,Ext 才会在 CommunityToolkit 弹出窗口中的 CarouselView 中溢出。
解决方法是将 .NET8 与最新的 CommunityToolkit Maui(版本 8.0.1)一起使用,这似乎可以解决该问题。
希望有帮助!