从ViewController返回后的MVVMCross数据绑定

时间:2014-12-08 14:56:40

标签: xamarin.ios xamarin mvvmcross

我使用MVVMCross 3.2.2作为iOS / Android应用程序的一部分。我的一个屏幕有多个视图显示,这取决于Tab栏中的选项,如按钮行。这些视图中的每一个都显示不同的数据,单独的UITableView。数据绑定完美无缺。

我还有一个菜单,其中有一个"个人资料"选择。更改配置文件会触发我的HomeView接收的MvxMessage,然后使用该消息将ViewModel设置为过滤要显示的数据。这一切似乎都很完美,数据显示正确。

如果我在HomeView中执行某些操作,使用ShowViewModel()显示另一个视图。当我返回到主视图时,在进行配置文件更改时,绑定不再正常工作。消息得到处理,数据被过滤,但是在UITableView上调用ReloadDataTable不会改变数据。

视图模型

    #region Groupings
    public IList<Group> Groups{
        get { return _groupService.GetAll(); }
    }

    public void SetupSubGroups(Group group)
    {
        if (group == null)
        {
            _groups = new ObservableCollection<Group> ();
            if (_profileService.SelectedProfile != null)
            {
                var grp = _groupService.GetByGroupName (_profileService.SelectedProfile.Name);
                if (grp == null)
                    grp = new Group { Name = _profileService.SelectedProfile.Name };
                _groups.Add (grp);
            }
        }
        else
        {
            var litsOfGroups = _groupService.GetSubGroups (group);
            foreach (var grp in litsOfGroups)
                _groups.Add (grp);
        }
        RaisePropertyChanged(() => AvailableGroups);
    }

    private ObservableCollection <Group> _groups;

    public ObservableCollection<Group> AvailableGroups {
        get { return _groups; }
    }
    #endregion

的ViewController

    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();

        var groupSource = new GroupTableViewDataSource (TableViewGroups);
        TableViewGroups.Source = groupSource;

        _localViewModel.SetupSubGroups (null);

        _bindingSet = this.CreateBindingSet<HomeViewController, HomeViewModel> ();
        _bindingSet.Bind (groupSource).To (vm => vm.AvailableGroups);
        _bindingSet.Apply ();
        TableViewReportTags.ReloadData ();

        NavigationController.NavigationBarHidden = false;
    }


    private void OnProfileChanged(ProfileChangedMessage message)
    {
        _localViewModel.SetupSubGroups (null);
        TableViewGroups.ReloadData ();
    }

    private HomeViewModel _localViewModel { get { return ViewModel as HomeViewModel; } }

我能看到或改变的任何想法都会非常有用。我花了很多时间在这上面,并没有取得任何进展。

0 个答案:

没有答案
相关问题