Question

My code looks similiar to this https://github.com/MvvmCross/MvvmCross-Tutorials/blob/master/Sample%20-%20CirriousConference/Cirrious.Conference.UI.Touch/Views/TwitterView.cs

In the TableSource class, is it possible to access the TwitterViewModel ViewModel Property without creating a new instance of the vm, making it static or using event-aggregation?

for example:

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

Solution

Since that class is nested within the View, you can just add access - exactly as you would any other C# class - e.g:

    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);
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top