Xamarin Forms-如何创建可在其中输入数量的显示警报?

时间:2018-08-09 06:21:08

标签: c# xaml xamarin xamarin.forms

我的应用是在线预订,您可以立即在网上选择您的订单并在指定的时间将其提供给您。

如何使这种显示警报? My Design 链接:https://i.stack.imgur.com/ycSMP.jpg

而不是“添加”,我还想要“取消”按钮,并且 您输入的数量也会转移到本地变量

这是我的代码

OrdernowMenu.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>

OrdernowMenu.xaml.cs

 public string json_response { get; set; }
        public string tester { get; set; }
        public string seletedMenu;
        public string menuPrice;
        public string quantity;

public OrdernowMenu(Data.PostSender posts1)
    {
        InitializeComponent();


          json_response = posts1.response;
        tester = posts1.teststring;
        GetUserAsync();
    }


private async Task GetUserAsync()
        { 

            var user = JsonConvert.DeserializeObject<List<Menus>>(json_response);

           MyOrder.ItemsSource = user;


        }



        private void MyOrder_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            var selectedOrder = e.SelectedItem as Menus;

            if (selectedOrder != null)
                seletedMenu = selectedOrder.menu_name;
            menuPrice = selectedOrder.menu_price;

            //How can i make it just like in the image? and store the value to quantity string
            //DisplayAlert(????);
            //quantity =  ????

        }

我试图研究它,但找不到它

我的参考:https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/pop-ups

3 个答案:

答案 0 :(得分:4)

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

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

答案 1 :(得分:1)

我建议您使用这个漂亮的插件:

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

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

然后单击“添加”按钮,我将向弹出窗口的调用者返回内容。 我有一个基本的弹出式实现,可以指定一个返回值。如果您需要该代码,我可以在这里共享(或在这里查看我的较早答案:Getting public variable of popped page

基本实现:

//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;
}

答案 2 :(得分:1)

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

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

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