为了账号安全,请及时绑定邮箱和手机立即绑定

Xamarin Forms - 如何创建一个显示警报,您可以在其中输入数量?

Xamarin Forms - 如何创建一个显示警报,您可以在其中输入数量?

白衣非少年 2021-11-21 14:45:32
我的应用程序是一个在线预订,您可以立即在线选择您的订单并在指定的时间为您服务。如何制作这种显示警报?而不是“添加”,我还想要“取消”按钮,您输入的数量也将转移到局部变量这是我的代码立即订购菜单.xaml<ListView x:Name="MyOrder" ItemSelected="MyOrder_ItemSelected" RowHeight="100">        <ListView.ItemTemplate>            <DataTemplate>                <ViewCell>                    <Grid ColumnSpacing="0" RowSpacing="0">                        <Grid.RowDefinitions>                            <RowDefinition Height="*" />                        </Grid.RowDefinitions>                        <Grid.ColumnDefinitions>                            <ColumnDefinition Width="*" />                            <ColumnDefinition Width="*" />                        </Grid.ColumnDefinitions>                        <StackLayout Grid.Row="0" Grid.Column="0" >                            <Image Source="{Binding menu_image ,StringFormat='https://i.imgur.com/{0:F0}.png'}"  Aspect="AspectFill"/>                        </StackLayout>                        <StackLayout Grid.Row="0" Grid.Column="1" VerticalOptions="Center">                            <Label Text="{Binding menu_name}" Font="30"/>                            <Label Text="{Binding menu_price,StringFormat='₱ {0:F0}'}" Font="20"/>                            <Label Text="{Binding menu_availability} " Font="10" />                        </StackLayout>                    </Grid>                </ViewCell>            </DataTemplate>        </ListView.ItemTemplate>    </ListView>
查看完整描述

3 回答

?
SMILET

TA贡献1796条经验 获得超4个赞

您可以创建自己的输入框对话框方法,而不是使用 DisplayAlert 或任何插件。官方 Xamarin.Form 论坛中有一个关于这个主题的好帖子。

Thomas Flemming 回答了该线程的链接https://forums.xamarin.com/discussion/comment/110002/#Comment_110002


查看完整回答
反对 回复 2021-11-21
?
人到中年有点甜

TA贡献1895条经验 获得超7个赞

最简单的方法是使用 NuGet 的 Acr.UserDialogs 包:https ://www.nuget.org/packages/Acr.UserDialogs/

将包包含在您的共享代码库和您的本机实现中,您可以通过一个简单的调用来启动对话框。

此外,我还描述了一种无需使用外部插件即可创建自定义对话框的方法:Display a popup with xamarin forms


查看完整回答
反对 回复 2021-11-21
?
RISEBY

TA贡献1856条经验 获得超5个赞

我建议你使用这个不错的插件:


https://github.com/rotorgames/Rg.Plugins.Popup


它让你创建一个完全自定义的弹出窗口(它在某处派生自 Xamarin.Forms.ContentPage),使用 XAML 或 C#,你可以像为任何其他页面那样创建布局。


然后点击“添加”按钮,我会向弹出窗口的调用者返回一些东西。我有一个基本的弹出实现,你可以指定一个返回值。如果您需要该代码,我可以在此处分享(或在此处查看我的旧答案:获取弹出页面的公共变量)


基本实现:


//Create a base callback-popup. Let any popup that should return something on a button click inherit from this

public class CallbackPopup<T> : PopupPage

{

    public Task<T> PagePoppedTask { get { return tcs.Task; } }

    private TaskCompletionSource<T> tcs;


    public CallbackPopup()

    {

        tcs = new TaskCompletionSource<T>();

    }


    //Deriving classes have to call this method in the "OnDisappearing" or when a specific button was clicked

    public void SetPopupResult(T result)

    {

        if (PagePoppedTask.IsCompleted == false)

            tcs.SetResult(result);

    }

}


//Asyncly call this popup

public async void OpenPopup(){

        var popup = new YourPopup<bool>();

        await Rg.Plugins.Popup.Services.PopupNavigation.Instance.PushAsync(popup);

        bool result = await popup.PagePoppedTask;

}


查看完整回答
反对 回复 2021-11-21
  • 3 回答
  • 0 关注
  • 229 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信