我有一个标签。当用户点击此标签时,它将显示带有条目的显示弹出窗口,以便用户可以键入消息。 Here is my image-
我该如何创建呢?
答案 0 :(得分:1)
选项一(简单方法):您可以使用某些插件,例如Rg.Plugins.Popup
选项二(艰难的方式):让它成为你自己的。这是我自己的选择,因为上面流行的插件不允许我使用任何自定义页面,如FreshMvvm页面。 在此选项中,我们应该为整个弹出窗口创建一个UI,使其 IsVisible 动态化。此外,在显示此弹出窗口时,将可能是整个页面的其他组件的IsEnabled设置为false。我们也可以选择性地动态更改整个页面的不透明度。这种方式的好处是一切都在我们的控制之下。
答案 1 :(得分:0)
这是here实施自定义输入提醒的一个很好的例子:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace acrossWords.Pages
{
public class ConfirmationPage : ContentPage
{
public bool result;
Image ConfirmButton;
Image CancelButton;
Label QuestionLabel;
public TaskCompletionSource<string> tcs;
public ConfirmationPage()
{
BackgroundImage = "ConfirmationPage.png";
QuestionLabel = new Label
{
FontFamily = "BookAntiqua",
//Margin = Margin = new Thickness(0, 5, 0, 0),
FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)) * 1.2,
Text = "",
TextColor = Xamarin.Forms.Color.White,
//HorizontalOptions = LayoutOptions.StartAndExpand,
//VerticalTextAlignment = Xamarin.Forms.TextAlignment.Center
};
ConfirmButton = new Image { Source = "ConfirmButton.png"};
CancelButton = new Image { Source = "CancelButton.png"};
AbsoluteLayout ConfirmLayout = new AbsoluteLayout { };
Content = ConfirmLayout;
AbsoluteLayout.SetLayoutFlags(ConfirmLayout, Xamarin.Forms.AbsoluteLayoutFlags.All);
AbsoluteLayout.SetLayoutBounds(ConfirmLayout, new Xamarin.Forms.Rectangle(0, 0, 1, 1));
ConfirmLayout.Children.Add(QuestionLabel, new Rectangle(0.3, 0.3, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize), AbsoluteLayoutFlags.PositionProportional);
ConfirmLayout.Children.Add(ConfirmButton, new Rectangle(0.2, 0.7, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize), AbsoluteLayoutFlags.PositionProportional);
ConfirmLayout.Children.Add(CancelButton, new Rectangle(0.8, 0.7, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize), AbsoluteLayoutFlags.PositionProportional);
ConfirmButton.GestureRecognizers.Add(new TapGestureRecognizer
{
NumberOfTapsRequired = 1,
Command = new Command(OnConfirm)
});
CancelButton.GestureRecognizers.Add(new TapGestureRecognizer
{
NumberOfTapsRequired = 1,
Command = new Command(OnCancel)
});
}
public void clearTCS()
{
tcs = new TaskCompletionSource<string>();
}
public async Task ShowConfirmation(string question)
{
QuestionLabel.Text = question;
await App.PushPage(this);
}
void OnConfirm()
{
tcs.SetResult("true");
App.PopPage();
}
void OnCancel()
{
tcs.SetResult("false");
App.PopPage();
}
}