Exemple #1
0
        private async void donateButton_Click(object sender, RoutedEventArgs e)
        {
            donateButton.IsEnabled = false;

            if (ApplicationInfo.Current.HasInternetConnection)
            {
                try
                {
                    ApplicationData.Current.RoamingSettings.Values["DonatePrompt"] = true;

                    var iapList = await PurchaseHelper.GetDonationsIAP();

                    ComboBox box = new ComboBox()
                    {
                        Margin = new Thickness(10, 10, 10, 0),
                        HorizontalAlignment = HorizontalAlignment.Stretch,
                    };


                    Button setButton = new Button()
                    {
                        IsEnabled           = false,
                        Content             = ApplicationInfo.Current.Resources.GetString("Proceed"),
                        Margin              = new Thickness(10, 10, 10, 0),
                        HorizontalAlignment = HorizontalAlignment.Stretch,
                    };



                    box.SelectionChanged += (snd, args) =>
                    {
                        if (box.SelectedItem != null)
                        {
                            setButton.IsEnabled = true;
                        }
                    };

                    setButton.Click += async(s, a) =>
                    {
                        ProductListing product = ((ComboBoxItem)box.SelectedItem).Tag as ProductListing;

                        ProductPurchaseStatus result = await PurchaseHelper.PurchaseAsync(product);

                        if (result == ProductPurchaseStatus.Succeeded)
                        {
                            PurchaseHelper.ShowDonationThanksMessage();
                        }
                        else
                        {
                            PurchaseHelper.ShowDonationErrorMessage();
                        }
                    };

                    foreach (ProductListing product in iapList)
                    {
                        ComboBoxItem cbi = new ComboBoxItem()
                        {
                            Tag     = product,
                            Content = product.FormattedPrice,
                        };
                        box.Items.Add(cbi);
                    }

                    Grid.SetColumn(box, 0);
                    Grid.SetColumn(setButton, 1);

                    PageHelper.MainPage.Notification.SetContent(ApplicationInfo.Current.Resources.GetString("AskForDonationTitle"),
                                                                ApplicationInfo.Current.Resources.GetString("AskForDonationMessage"),
                                                                "", new System.Collections.Generic.List <UIElement>()
                    {
                        box, setButton
                    });

                    PageHelper.MainPage.Notification.Show();
                }
                catch
                {
                    //await nf1.Show(res.GetString("AskForDonationErrorMessage"), res.GetString("AskForDonationErrorTitle"), btn1, btn2);
                }
            }
            else
            {
            }

            donateButton.IsEnabled = true;
        }