C# xamarin表单-从选择器中选择后重新加载选择器UI

C# xamarin表单-从选择器中选择后重新加载选择器UI,c#,xaml,xamarin,xamarin.forms,picker,C#,Xaml,Xamarin,Xamarin.forms,Picker,Xamarin表单-创建一个应用程序,使用listView和picker作为数量选择。为了测试,我添加了3条ProductModel记录 在屏幕上,没有明显的原因,有时会发生,但不总是……当从listview中选择第二个或第三个productModel时,会出现选择器弹出窗口……用户从选择器中选择一个数字。当他们选择号码时,选择器关闭并重新打开 我们一直在试图找到这种情况发生的确切用例,但看不到……只知道它从未在第一条记录中发生过。只有第二和第三 谢谢 //Product Model p

Xamarin表单-创建一个应用程序,使用listView和picker作为数量选择。为了测试,我添加了3条ProductModel记录

在屏幕上,没有明显的原因,有时会发生,但不总是……当从listview中选择第二个或第三个productModel时,会出现选择器弹出窗口……用户从选择器中选择一个数字。当他们选择号码时,选择器关闭并重新打开

我们一直在试图找到这种情况发生的确切用例,但看不到……只知道它从未在第一条记录中发生过。只有第二和第三

谢谢

    //Product Model
public class ProductModel : INotifyPropertyChanged
    {
 public event PropertyChangedEventHandler PropertyChanged;

 private int _ProductId;
        private string _ProductName;
        private string _Quantity;
        private string tempQuantity = "-1";

        //Constructor
        public ProductModel()
        {
            //Subscription
            this.PropertyChanged += OnPropertyChanged;
        }

 [PrimaryKey, AutoIncrement]
        public int ProductId
        {
            get { return _ProductId; }
            set
            {
                if (_ProductId == value) return;
                _ProductId = value;
                OnPropertyChanged();
            }
        }


        //Properties
        public string Quantity
        {
            get {
                return _Quantity;
            }
            set
            {
                _Quantity = value;
                OnPropertyChanged();
            }
        }

  public string ProductName
        {
            get { return _ProductName; }
            set
            {
                _ProductName = value;
                OnPropertyChanged();
            }
        }

 private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == nameof(Quantity))
            {
                //test quantity amount
            }
        }

        // [NotifyPropertyChangedInvocator]
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
}


//ProductPageViewModel
public class ProductPageViewModel : BindableObject, INotifyPropertyChanged
    {
        public ObservableCollection<ProductModel> WineList { get; set; }

        public ProductPageViewModel()
        {
  WineList = new ObservableCollection<ProductModel>();
            WineList.Add(new ProductModel
            {
                ProductId = 1,
                ProductName = "Wine 101",//,
                Quantity = "0"
            });
            WineList.Add(new ProductModel
            {
                ProductId = 2,
                ProductName = "Wine 102",//,
                Quantity = "0"
            });
            WineList.Add(new ProductModel
            {
                ProductId = 3,
                ProductName = "Wine 103",//,
                Quantity = "0"
            });
}

}

//ProductPage.xaml
 <ContentPage.Content>
        <StackLayout>

            <ListView  x:Name="producttablelist" IsVisible="True" VerticalOptions="FillAndExpand" HasUnevenRows="True" ItemsSource="{Binding WineList}" HeightRequest="1500">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <StackLayout HeightRequest="120" BackgroundColor="Green" HorizontalOptions="StartAndExpand">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="Auto"/>
                                    </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Label Grid.Row="0" Grid.Column="0" Text="{Binding ProductName}" TextColor="Black" VerticalOptions="Start"></Label>

                                    <Picker Grid.Column="4" Grid.Row="2" VerticalOptions="Start"  SelectedIndex="{Binding Quantity, Mode=TwoWay}">
                                        <Picker.Items>
                                            <x:String>0</x:String>
                                            <x:String>1</x:String>
                                            <x:String>2</x:String>
                                            <x:String>3</x:String>
                                            <x:String>4</x:String>
                                            <x:String>5</x:String>
                                            <x:String>6</x:String>
                                        </Picker.Items>
                                    </Picker>
                                </Grid>
                            </StackLayout>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </StackLayout>
       
    </ContentPage.Content>
</ContentPage>


//ProductPage.xaml.cs
[XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class ProductPage : ContentPage
    {
        public ProductPageViewModel productPage_ViewModal;
  public ProductPage()
        {
            InitializeComponent();
            productPage_ViewModal = new ProductPageViewModel();
            BindingContext = productPage_ViewModal;
        }
}
//产品模型
公共类ProductModel:INotifyPropertyChanged
{
公共事件属性更改事件处理程序属性更改;
私有int_ProductId;
私有字符串“\u ProductName”;
私有字符串_数量;
私有字符串tempQuantity=“-1”;
//建造师
公共产品模型()
{
//订阅
this.PropertyChanged+=OnPropertyChanged;
}
[主密钥,自动增量]
公共int ProductId
{
获取{return\u ProductId;}
设置
{
if(_ProductId==value)返回;
_ProductId=值;
OnPropertyChanged();
}
}
//性质
公共字符串数量
{
得到{
退货数量;
}
设置
{
_数量=价值;
OnPropertyChanged();
}
}
公共字符串产品名称
{
获取{return\u ProductName;}
设置
{
_产品名称=价值;
OnPropertyChanged();
}
}
私有void OnPropertyChanged(对象发送方,PropertyChangedEventArgs e)
{
如果(e.PropertyName==名称(数量))
{
//测试量
}
}
//[NotifyPropertyChangedInvocator]
受保护的虚拟void OnPropertyChanged([CallerMemberName]字符串propertyName=null)
{
PropertyChanged?.Invoke(这是新的PropertyChangedEventArgs(propertyName));
}
}
//ProductPageViewModel
公共类ProductPageViewModel:BindableObject,INotifyPropertyChanged
{
公共ObservableCollection酒单{get;set;}
公共产品页面视图模型()
{
WineList=新的ObservableCollection();
WineList.Add(新产品型号)
{
ProductId=1,
ProductName=“Wine 101”,/,
数量=“0”
});
WineList.Add(新产品型号)
{
ProductId=2,
ProductName=“Wine 102”,/,
数量=“0”
});
WineList.Add(新产品型号)
{
ProductId=3,
ProductName=“Wine 103”,/,
数量=“0”
});
}
}
//ProductPage.xaml
0
1.
2.
3.
4.
5.
6.
//ProductPage.xaml.cs
[XamlCompilation(XamlCompilationOptions.Compile)]
公共部分类ProductPage:ContentPage
{
公共产品页面视图模型产品页面\视图模式;
公共产品页()
{
初始化组件();
productPage_ViewModal=新ProductPageViewModel();
BindingContext=productPage\u ViewModal;
}
}

我使用上面的代码进行测试,但无法再现问题。从您的问题和代码中不清楚发生了什么。我建议您在一个空白项目中重新创建该问题,然后将其上载到GitHub,供人们运行并查看