猿问

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

我的应用程序是一个在线预订,您可以立即在线选择您的订单并在指定的时间为您服务。

如何制作这种显示警报?

而不是“添加”,我还想要“取消”按钮,您输入的数量也将转移到局部变量


这是我的代码


立即订购菜单.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>


白衣非少年
浏览 230回答 3
3回答

SMILET

您可以创建自己的输入框对话框方法,而不是使用 DisplayAlert 或任何插件。官方 Xamarin.Form 论坛中有一个关于这个主题的好帖子。Thomas Flemming 回答了该线程的链接https://forums.xamarin.com/discussion/comment/110002/#Comment_110002

人到中年有点甜

最简单的方法是使用 NuGet 的 Acr.UserDialogs 包:https&nbsp;://www.nuget.org/packages/Acr.UserDialogs/将包包含在您的共享代码库和您的本机实现中,您可以通过一个简单的调用来启动对话框。此外,我还描述了一种无需使用外部插件即可创建自定义对话框的方法:Display a popup with xamarin forms

RISEBY

我建议你使用这个不错的插件: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 thispublic class CallbackPopup<T> : PopupPage{&nbsp; &nbsp; public Task<T> PagePoppedTask { get { return tcs.Task; } }&nbsp; &nbsp; private TaskCompletionSource<T> tcs;&nbsp; &nbsp; public CallbackPopup()&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; tcs = new TaskCompletionSource<T>();&nbsp; &nbsp; }&nbsp; &nbsp; //Deriving classes have to call this method in the "OnDisappearing" or when a specific button was clicked&nbsp; &nbsp; public void SetPopupResult(T result)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; if (PagePoppedTask.IsCompleted == false)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tcs.SetResult(result);&nbsp; &nbsp; }}//Asyncly call this popuppublic async void OpenPopup(){&nbsp; &nbsp; &nbsp; &nbsp; var popup = new YourPopup<bool>();&nbsp; &nbsp; &nbsp; &nbsp; await Rg.Plugins.Popup.Services.PopupNavigation.Instance.PushAsync(popup);&nbsp; &nbsp; &nbsp; &nbsp; bool result = await popup.PagePoppedTask;}
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答