xamarin.forms - 在 Xamarin 表单中向下滚动时关闭 Rg.Plugins.Popup
问题描述
我在我的 xamarin 表单应用程序中使用Rg.Plugins.Popup插件。这是一个很好的模态对话框插件。但是,我希望在用户向下滚动时关闭对话框。(iOS 中的大多数对话框都有这种向下滚动关闭的行为)。
弹出页面内的 XAML。
选项1
<pages:PopupPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup"
HasSystemPadding="True"
CloseWhenBackgroundIsClicked="False"
x:Name="MyPage"
x:Class="wQuran.Views.Today.PrayerTimesSettingsPopupPage">
<Frame Style="{DynamicResource PopupFrame}" VerticalOptions="FillAndExpand" IsClippedToBounds="True">
<Grid RowDefinitions="Auto,*" Style="{DynamicResource BaseGrid}">
<BoxView Grid.Row="0" Style="{DynamicResource PopupTitleBoxView}"/>
<Grid Grid.Row="0" ColumnDefinitions="*,30" HeightRequest="40" Padding="10">
<Label Grid.Column="0" Text="{Binding Title}" Style="{DynamicResource PopupTitleLabel}"/>
<ImageButton Grid.Column="1" Style="{DynamicResource DialogCloseImageButton}" Command="{Binding CloseDialogCommand}"/>
</Grid>
</Grid>
</Frame>
</pages:PopupPage>
选项 2. 更新 XAML 并在 ScrollView 中添加 Frame
<ScrollView Scrolled="ScrollView_Scrolled">
....
</ScrollView>
private void ScrollView_Scrolled(object sender, Xamarin.Forms.ScrolledEventArgs e)
{
if (e.ScrollY > 100)
{
itemViewModel.CloseDialogCommand.Execute(null);
}
}
在选项 1 中,我没有滚动,因此插件以默认行为工作,但我无法关闭滚动中的对话框。
在选项 2 中,我在滚动视图中添加了框架以检查 Y 滚动并关闭对话框。Scrolled 事件永远不会触发。此外,在模式外部单击时,我无法关闭对话框。
毕竟,我的问题是如何在向下滚动时关闭对话框?
解决方案
毕竟,我的问题是如何在向下滚动时关闭对话框?
我猜你想在 ScrollView 滚动结束时关闭 PopupPage。如果是,请查看以下代码:
<pages:PopupPage
x:Class="FormsSample.simplecontrol.Page16"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup">
<StackLayout
Padding="20,0"
HorizontalOptions="FillAndExpand"
VerticalOptions="Center">
<Frame
Padding="0"
BackgroundColor="CadetBlue"
CornerRadius="10"
HeightRequest="100">
<ScrollView Scrolled="ScrollView_Scrolled">
<StackLayout Padding="10">
<Label
FontSize="20"
HorizontalOptions="Center"
Text="First Popup Page"
TextColor="Black" />
<Label Text="Hello Xamarin Guys" TextColor="Red" />
<Label Text="This is Very Awesome Popup Plugins For Xamarin forms" TextColor="LightBlue" />
<Button Text="Close" TextColor="Black" />
<Image Source="a11.jpg" />
</StackLayout>
</ScrollView>
</Frame>
</StackLayout></pages:PopupPage>
private async void ScrollView_Scrolled(object sender, ScrolledEventArgs e)
{
ScrollView scrollView = sender as ScrollView;
double scrollingSpace = scrollView.ContentSize.Height - scrollView.Height;
if (scrollingSpace <= e.ScrollY) // Touched bottom
// Do the things you want to do
await PopupNavigation.Instance.PopAsync();
}
推荐阅读
- uml - 在 Sparx Enterprise Architect UML Profile 中为非 UML 元素定义 Stereotype 似乎不起作用
- json - 如何将日期值解析为 SonarAPI 调用
- wpf - 如何在另一个 RadGridView 的 RowDetailsTemplate 中绑定一个 RadGridView
- r - 为什么 `map2_chr` 有时会返回 `character(0)`?
- java - 有没有一种方法可以为 Sentry 添加范围并在 Sentry-Java 中添加跟踪信息。?
- firebase - Firebase:我可以在登录前知道“ERROR_INVALID_EMAIL”的规则吗?
- selenium - 如何使用来自用户输入的实时数据创建动态 xpath 并放入我的 xpath?
- c# - 带有 using 语句的 C# 嵌套流,我应该使用两个 using 吗?
- javascript - 为什么 Chart.js(类型:时间)显示错误的标签
- swift - persistentContainer.newBackgroundContext() 不使用 context.existingObject(with:) 上的更新对象