【发布时间】:2018-06-05 15:15:54
【问题描述】:
我有一个标签。当用户点击此标签时,它将显示一个带有条目的显示弹出窗口,以便用户可以键入消息。 Here is my image-
我怎样才能创建这个?
【问题讨论】:
标签: user-interface xamarin xamarin.forms
我有一个标签。当用户点击此标签时,它将显示一个带有条目的显示弹出窗口,以便用户可以键入消息。 Here is my image-
我怎样才能创建这个?
【问题讨论】:
标签: user-interface xamarin xamarin.forms
选项一(简单的方法):您可以使用一些插件,例如Rg.Plugins.Popup
选项二(艰难的方式): 将它变成你自己的。这是我自己的选择,因为上面流行的插件不允许我使用任何自定义页面,例如 FreshMvvm 页面。 在这个选项中,我们应该为整个弹出窗口创建一个 UI,使其 IsVisible 动态化。在显示此弹出窗口时,还将可能是整个页面的 IsEnabled 的其他组件设置为 false。我们也可以选择动态地更改整个页面的不透明度。这种方式的好处是一切都在我们的掌控之中。
【讨论】:
这是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();
}
}
【讨论】: