微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ListView更新不会更新值

如何解决ListView更新不会更新值

用户可以更新值时,我正在列表视图中显示数据,并且在所选项目上显示弹出窗口

现在,当我单击一个字段并在返回原始页面时对其进行编辑时,该值将保持与更新前相同。我已将属性设置为相同的模型数据,并在调试时在属性“字段值”中设置为停止,但该值不会更改。你能帮忙吗

ListView 
 <ListView BackgroundColor="{DynamicResource PageBackgroundColor}" x:Name="list"  
                        HasUnevenRows="True"
                        IsPullToRefreshEnabled="True"
                        SelectedItem="{Binding SelectedItem,Mode=TwoWay}"
                        CachingStrategy="RecycleElement"
                        ItemsSource="{Binding Results,Mode=TwoWay}"
                        SeparatorVisibility="Default" >
                        <ListView.ItemTemplate>
                            <DataTemplate>
                            <ViewCell>
                                    <Grid  BackgroundColor="{DynamicResource PageBackgroundColor}">
                                   <!--Data-->
                                       <Label  Padding="10,4,4" Text ="{Binding FieldDescriptor}" Style="{StaticResource SubLabelBlackStyle}" HorizontalOptions="Start" BackgroundColor="{DynamicResource PageBackgroundColor}" HorizontalTextAlignment="Start"      />
                                       <Label Grid.Column="3"  Text="{Binding FieldValue,Mode=TwoWay}" Style="{StaticResource SubLabelBlackStyle}" HorizontalOptions="Start" BackgroundColor="{DynamicResource PageBackgroundColor}" HorizontalTextAlignment="Start"  >
                                         
                                       </Label>
                                      
                          
                                  </Grid>
                            </ViewCell>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>

PopUP

 <Grid Grid.Row="1"  BackgroundColor="{DynamicResource SeparatorLineColor}"
                  HorizontalOptions="FillAndExpand" >
                   <Entry  BackgroundColor="{DynamicResource SeparatorLineColor}"
                           Margin="10,0"
                           Grid.ColumnSpan="2" 
                    HorizontalOptions="Start" WidthRequest="150"
                    Placeholder="{Binding FieldValue}"
                    Text="{Binding FieldValue}"
                Style="{StaticResource SubLabelBlackStyle}"
                    ReturnType="Next">
                 </Entry>
                </Grid>
      </Grid>

 public EditPopUp(DocumentData param,ResultPageviewmodel model,int index)
        {
            InitializeComponent();
            BindingContext = new EditPopUpviewmodel(param,model,index);
          
        }

public async Task UpdateValue(DocumentData selectedItem,int index)
        {
            Results.Insert(index,selectedItem);
        }

        private void OnItemSelected(DocumentData selectedItem)
        {
            var index = Results.IndexOf(selectedItem);
            Results.Remove(selectedItem);
            Navigation.PushPopupAsync(new EditPopUp(selectedItem,this,index));
        }

还有我的POP UP班

 public class EditPopUpviewmodel : Baseviewmodel
    {
     
        private DocumentData _fieldValue;
        private string _fieldValueString;
        private string _fieldDescriptor;
        private int _num;
    
        public Command CancelPopUpCommand { get; }
        public Command ConfirmPopUpCommand { get; }

        public DocumentData FieldValue
        { get
            { return _fieldValue; }

            set
            {
                if (_fieldValue != value)
                { _fieldValue = value;
                    
               OnPropertyChanged("FieldValue"); }
            }
        }

        public string FieldValueString
        {
            set
            {
                _fieldValueString = value;

                NotifyPropertyChanged(nameof(FieldValue));
            }
            get { return _fieldValueString; }
        }

        public string FieldDescriptor
        {
            set
            {
                _fieldDescriptor = value;

                NotifyPropertyChanged(nameof(FieldDescriptor));
            }
            get { return _fieldDescriptor; }
        }

        public int Num
        {
            set
            {
                _num = value;

                NotifyPropertyChanged(nameof(FieldValue));
            }
            get { return _num; }
        }

        public void Load(DocumentData param,int index)
        {
            FieldValue = param;
            FieldValueString = param.FieldValue;
            FieldDescriptor = param.FieldDescriptor;
            Num = index;
        }

        public EditPopUpviewmodel(DocumentData param,int index)
        {
           
            Load(param,index);

            ConfirmPopUpCommand = new Command(async () => await ExecuteConfirmPopUpCommand(model));
            CancelPopUpCommand = new Command(async () => await ExecuteCancelPopUpCommand());
        }

        private async Task ExecuteCancelPopUpCommand()
        {
            await PopupNavigation.Instance.PopAsync(true);
        }

        private async Task ExecuteConfirmPopUpCommand(ResultPageviewmodel model)
        {
             model.UpdateValue(FieldValue,Num);
            await PopupNavigation.Instance.PopAsync(true);
        }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。