编辑后弹出 RG 插件没有更新属性 [英] Popup RG plugins after edit no update for property

查看:22
本文介绍了编辑后弹出 RG 插件没有更新属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在列表中显示我的属性.我曾经使用 Acr.UserDialogs 来显示弹出窗口,但我决定改用 RG 以获得更好的 UI.

I am displaying my properties in list. I used to use Acr.UserDialogs to display popup however I have decided to switch to RG for better UI.

现在,当我在一个字段上计时并在返回原始页面时对其进行编辑时,该值保持与更新前相同.我曾尝试添加 RefreshPull 但这无济于事

Now when I clock on one field and edit it when I go back to the original page the value stay the same as it was before update. I have tried to add RefreshPull but that doesn't help

我的页面背面

  public DisplayResult(RemoteCallResult<IEnumerable<DocumentData>> data)
        {
            InitializeComponent();
            BindingContext = _resultPageViewModel = new ResultPageViewModel(data);
        }

我的 Xaml

<ListView BackgroundColor="{DynamicResource PageBackgroundColor}" x:Name="list"  IsPullToRefreshEnabled="{Binding Update}"
                       ItemsSource="{Binding Results, Mode=TwoWay}"
                        SeparatorVisibility="Default"
                        SelectionMode="None">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                            <ViewCell>
                                    <Grid  BackgroundColor="{DynamicResource PageBackgroundColor}">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="4*"/>
                                            <ColumnDefinition Width="12*"/>
                                             <ColumnDefinition Width="*"/>
                                            <ColumnDefinition Width="12*"/>
                                            <ColumnDefinition Width="4*"/>
                                        </Grid.ColumnDefinitions>
                                 
                                       <Label Grid.Column="1" Padding="0,3,3,0" Text ="{Binding FieldDescriptor}" Style="{StaticResource SubLabelBlackStyle}" HorizontalOptions="Start" BackgroundColor="{DynamicResource PageBackgroundColor}" HorizontalTextAlignment="Start"  />
                                       <Label Grid.Column="3" Padding="0,3,3,0" Text="{Binding FieldValue, Mode=TwoWay}" Style="{StaticResource SubLabelBlackStyle}" HorizontalOptions="Start" BackgroundColor="{DynamicResource PageBackgroundColor}" HorizontalTextAlignment="Start"  >
                                           <Label.GestureRecognizers>
                                               <TapGestureRecognizer Command="{Binding BindingContext.EditTextCommand, Source={x:Reference Name=list}}"  CommandParameter="{Binding .}"/>
                                           </Label.GestureRecognizers>
                                       </Label>
                                  </Grid>
                            </ViewCell>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView> 

视图模型

 public string FieldValue
        {
            get => _fieldValue;
            set => SetValue(ref _fieldValue, value);
        }
        public ResultPageViewModel()
        {

        }

        public ResultPageViewModel(RemoteCallResult<IEnumerable<DocumentData>> data)
        {
            EditTextCommand = new Command<DocumentData>(async (key) => await EditTextAsync(key));
            Update = new Command<string>(async (key) => await UpdateValue(key));
            LoadText(data);        }

  public async Task EditTextAsync(DocumentData param)
        {
            await Navigation.PushPopupAsync(new EditPopUp(param));
        }

        public async Task UpdateValue(string value)
        {
            _fieldValue = value;
        }

视图模型弹出

 private readonly ResultPageViewModel _resultPageViewModel;
        private string _fieldValue;
        public Command ConfirmPopUpCommand { get; }

        public string FieldValue
        {
            set
            {
                _fieldValue = value;

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


        public EditPopUpViewModel(DocumentData param)
        {
            _resultPageViewModel = new ResultPageViewModel();
            _fieldValue = param.FieldValue;
            ConfirmPopUpCommand = new Command(async () => await ExecuteConfirmPopUpCommand());
          
        }

        private async Task ExecuteConfirmPopUpCommand()
        {
    
            await _resultPageViewModel.UpdateValue(_fieldValue);
            await PopupNavigation.Instance.PopAsync(true);
        }

弹出

  <Entry x:Name="entryCardName"
                    FontSize="Small"
                    Placeholder="{Binding FieldValue}"
                    Text="{Binding FieldValue}"
                    TextColor="Black"
                    ReturnType="Next">
                </Entry>

推荐答案

当你显示弹出窗口时,我认为你也应该将 ViewModel 传递给 popupPage:

When you show the pop up, I think you should also pass the ViewModel to the popupPage:

  public async Task EditTextAsync(DocumentData param)
        {
            await Navigation.PushPopupAsync(new EditPopUp(param), this);
        }

然后在 POPUP 中,就不需要新建一个了:

Then in the POPUP, you does not need to create a new one:

public MainPage(DocumentData param, ResultPageViewModel model)
{
    _fieldValue = param.FieldValue;
    Command ConfirmPopUpCommand = new Command(async () => await ExecuteConfirmPopUpCommand(model));

}

private async Task ExecuteConfirmPopUpCommand(ResultPageViewModel model)
{

    await model.UpdateValue(_fieldValue);
    await PopupNavigation.Instance.PopAsync(true);
}

这篇关于编辑后弹出 RG 插件没有更新属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆