C# 从表源访问ViewModel

C# 从表源访问ViewModel,c#,xamarin.ios,mvvmcross,C#,Xamarin.ios,Mvvmcross,我的代码看起来与此类似 在TableSource类中,是否可以访问TwitterViewModel ViewModel属性而不创建vm的新实例、使其成为静态或使用事件聚合 例如: public override float GetHeightForRow (UITableView tableView, NSIndexPath indexPath) { return ViewModel.DoGetHeightForRow(); } 由于该类嵌套在视图中,因此您只需添加访问权限,就像添加任

我的代码看起来与此类似

在TableSource类中,是否可以访问TwitterViewModel ViewModel属性而不创建vm的新实例、使其成为静态或使用事件聚合

例如:

public override float GetHeightForRow (UITableView tableView, NSIndexPath indexPath)
{
    return ViewModel.DoGetHeightForRow();
}

由于该类嵌套在视图中,因此您只需添加访问权限,就像添加任何其他C#类一样,例如:

    public class TableSource : MvxSimpleTableViewSource
    {
        private TwitterView _parent;

        public TableSource (UITableView tableView, TwitterView parent)
            : base(tableView, TweetCell3.Identifier, TweetCell3.Identifier)
        {
            _parent = parent;
            tableView.RegisterNibForCellReuse(UINib.FromName(TweetCell3.Identifier, NSBundle.MainBundle), TweetCell3.Identifier);
        }

        public override float GetHeightForRow (UITableView tableView, NSIndexPath indexPath)
        {
            return _parent.SomeMethod(indexPath);
        }
    }

我想我应该休息一下。。似乎太累了,或者代码太多让我困惑,谢谢:-)