我正在用MAUI和NET8创建一个应用程序。我在Windows上遇到了一个有趣的问题。请考虑下面的屏幕截图
的数据
基本上,这是一个ListView
<ListView x:Name="listDictionaries"
x:DataType="vm:DictionaryListViewModel"
ItemsSource="{Binding Dictionaries}"
ItemSelected="listDictionaries_ItemSelected"
SelectionMode="Single" HasUnevenRows="True"
CachingStrategy="RecycleElement"
HorizontalOptions="Fill" VerticalOptions="Fill"
IsRefreshing="{Binding IsRefreshing}"
RefreshCommand="{Binding RefreshCommand}">
<ListView.ItemTemplate>
<DataTemplate x:DataType="dt:Dictionary">
<ViewCell>
<!-- UI stuff -->
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
字符串
它正在工作。如果我调整窗口大小,则不可能以任何方式滚动ListView
。此外,我在 MauiProgram.cs 中添加了这些行:
.ConfigureLifecycleEvents(events =>
{
#if WINDOWS
events.AddWindows(windows => windows
.OnWindowCreated(window =>
{
window.SizeChanged += OnSizeChanged;
}));
#endif
})
型
在文件的底部
#if WINDOWS
static void OnSizeChanged(object sender,
Microsoft.UI.Xaml.WindowSizeChangedEventArgs args)
{
ILifecycleEventService service = MauiWinUIApplication.Current.Services.GetRequiredService<ILifecycleEventService>();
service.InvokeEvents(nameof(Microsoft.UI.Xaml.Window.SizeChanged));
}
#endif
型
但它并不起作用。这里有一个活生生的例子,
的
我该怎么补救?
1条答案
按热度按时间14ifxucb1#
在这里分享两个解决方案。
选项1,使用**VerticalOptions=“FillAndExpand”**代替VerticalOptions=“Fill”
字符串
Option2,使用Grid(而不是StackLayout)作为外部容器,
型
以上两种方法都可以使ListView滚动。
希望对你有帮助。