我的 MainPage.Xaml 中有以下布局
<RefreshView x:Name="refreshView"
IsRefreshing="{Binding IsRefreshing}"
Refreshing="refreshView_Refreshing"
AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All">
<WebView Source="https://csharpforums.net/forums/maui" />
<RefreshView>
当我向下滚动、停止,然后尝试向上滚动时,它会尝试刷新而不是向上滚动。 这里说我需要在 RefreshView 中放置一个滚动视图才能工作 -> https://learn.microsoft.com/en-us/samples/dotnet/maui-samples/userinterface-refreshview/ 但问题是,在滚动视图中包含一个 web 视图有它自己的 bug -> https://stackoverflow.com/questions/33688701/webview-height-grows-indefinitely-inside-a-nestedscrollview#:~:text=In %20one%20sentence%2C%20you%20just%20can%27t%20put%20your%20WebView%20inside%20NestedScrollView.%20This%20is%20working%20as%20预期.
如何在MAUI中实现webview的下拉刷新?
您可以尝试以下代码:
xaml:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiApp2.NewPage1"
Title="NewPage1">
<RefreshView x:Name="refreshView"
Refreshing="refreshView_Refreshing">
<ScrollView>
<WebView x:Name="webview"
Source="https://learn.microsoft.com/en-us/dotnet/maui/user-interface/controls/refreshview?view=net-maui-8.0"/>
</ScrollView>
</RefreshView>
</ContentPage>
xaml.cs:
public partial class NewPage1 : ContentPage
{
public NewPage1()
{
InitializeComponent();
}
private void refreshView_Refreshing(object sender, EventArgs e)
{
refreshView.IsRefreshing = true;
webview.Reload();
refreshView.IsRefreshing = false;
}
}