gpt4 book ai didi

xamarin - Xamarin.Forms 中的自定义弹出窗口

转载 作者:行者123 更新时间:2023-12-01 11:27:02 24 4
gpt4 key购买 nike

有什么方法可以使用 Xamarin Forms 在其中创建带有编辑器的自定义弹出对话框。针对iOS平台。

我想要一个带有标题标签的弹出窗口,用于接受输入的文本框和用于显示错误消息的错误标签,带有确定和取消按钮。

我想从输入弹出窗口接受 pin 号并且必须验证 pin。如果验证失败,我必须在弹出窗口中显示错误消息。

谢谢,

最佳答案

这是一个很好的 XF 弹出窗口,其中包括向弹出窗口添加编辑器的功能。

Popup Page Plugin for Xamarin Forms

// Use these methods in PopupNavigation globally or Navigation in your pages

// Open new PopupPage
Task PushAsync(PopupPage page, bool animate = true) // Navigation.PushPopupAsync

// Hide last PopupPage
Task PopAsync(bool animate = true) // Navigation.PopPopupAsync

// Hide all PopupPage with animations
Task PopAllAsync(bool animate = true) // Navigation.PopAllPopupAsync

// Remove one popup page in stack
Task RemovePageAsync(PopupPage page, bool animate = true) // Navigation.RemovePopupPageAsync

XAML 弹出页面
<?xml version="1.0" encoding="utf-8" ?>
<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"
xmlns:animations="clr-namespace:Rg.Plugins.Popup.Animations;assembly=Rg.Plugins.Popup"
x:Class="Demo.Pages.MyPopupPage">
<!--Animations use example-->
<pages:PopupPage.Animation>
<animations:ScaleAnimation
PositionIn="Center"
PositionOut="Center"
ScaleIn="1.2"
ScaleOut="0.8"
DurationIn="400"
DurationOut="300"
EasingIn="SinOut"
EasingOut="SinIn"
HasBackgroundAnimation="True"/>
</pages:PopupPage.Animation>
<!-- Content -->
</pages:PopupPage>

弹出页面
public partial class MyPopupPage : PopupPage
{
public SecondPopupPage()
{
InitializeComponent();
}

protected override void OnAppearing()
{
base.OnAppearing();
}

protected override void OnDisappearing()
{
base.OnDisappearing();
}

// Method for animation child in PopupPage
// Invoced after custom animation end
protected virtual Task OnAppearingAnimationEnd()
{
return Content.FadeTo(0.5);
}

// Method for animation child in PopupPage
// Invoked before custom animation begin
protected virtual Task OnDisappearingAnimationBegin()
{
return Content.FadeTo(1);;
}

protected override bool OnBackButtonPressed()
{
// Prevent hide popup
//return base.OnBackButtonPressed();
return true;
}

// Invoced when background is clicked
protected override bool OnBackgroundClicked()
{
// Return default value - CloseWhenBackgroundIsClicked
return base.OnBackgroundClicked();
}
}

主页
    // Main Page

public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}

// Button Click
private async void OnOpenPupup(object sender, EventArgs e)
{
var page = new MyPopupPage();

await Navigation.PushPopupAsync(page);
// or
await PopupNavigation.PushAsync(page);
}
}

关于xamarin - Xamarin.Forms 中的自定义弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36441913/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com