首页 > 解决方案 > Binding 的值没有显示在 ios 中,但在 android 上正常工作

问题描述

当显示具有两个数据绑定的页面时,值会在 android 中完美显示,如下所示:

安卓模拟器截图

但是在 ios 上运行时,只显示其中一个值:

iOS模拟器截图(iOS版本14.1)

页面的 xaml 代码如下所示:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MultiTest.PaymentPage"
             Title="Confirm Payment">
    <ContentPage.Content>
        <StackLayout Margin ="20" Spacing="5">
            <Label Text="Top Up Value: "
                   VerticalTextAlignment="Center"
               />
            <Label Text="{Binding Denominations}"
                   VerticalTextAlignment="Center"
                
                   x:Name="TopUpValue"/>
            <Label Text="Meter Number:"
                   VerticalTextAlignment="Center"
                />
            <Label Text="{Binding MeterNumber}"  VerticalTextAlignment="Center"
              
                   x:Name="CreditCardDetails"/>
            <Button Text="To Payment" Clicked="ToConfirmPayment"/>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

ios版本中是否缺少一些额外的配置?

编辑:这是应用程序背后的一些代码:

Payment.cs(用于存储所需数据的类):

using System;
using System.Collections.Generic;
using System.Text;

namespace MultiTest.Models
{
    public class Payment
    {
        public string Denominations { get; set; }
        public string MeterNumber { get; set; }

        public override string ToString()
        {
            return MeterNumber;
        }



    }
}

ConfirmTopUp.xaml.cs(视图背后的代码):

using System.Text;
using System.Threading.Tasks;
using MultiTest.Models;
using MultiTest.ViewModel;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace MultiTest
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class PaymentPage : ContentPage
    {

       //public Payment topUp;
        public PaymentPage()
        {
            InitializeComponent();
            BindingContext = new Payment();
        }

        async void ToConfirmPayment(object sender, EventArgs args)
        {
            await Navigation.PushAsync(new PaymentConfirmation());
        }
    }
}

TopUpOptions.xaml.cs(从中传递数据的视图):

  var paymentDetails = new Payment
                        {
                            Denominations = topUpValue.ToString(),
                            MeterNumber = meter.MeterNumber
                        };

                        var toPayment = new PaymentPage();
                        toPayment.BindingContext = paymentDetails;
                        await Navigation.PushAsync(toPayment);

标签: androidiosxamarin.forms

解决方案


推荐阅读