I am am trying to create a tabbed view using the Cirrious Conference sample but seem to be having problems displaying my data. The problem arises when the view which hosts the tab is invoked specifically at the code below
// Initialize a TabSpec for each tab and add it to the TabHost
spec = TabHost.NewTabSpec("welcome");
spec.SetIndicator(this.GetText("Welcome"),Resources.GetDrawable(Resource.Drawable.Tab_Welcome));
spec.SetContent(CreateIntentFor(ViewModel.Welcome));
TabHost.AddTab(spec);
My ViewModel calss is below
public class WelcomeViewModel : MvxViewModel
{
private string _description;
public string Description
{
get
{
return _description;
}
set
{
_description = value;
FirePropertyChanged("Description");
}
}
public WelcomeViewModel(string description)
{
Description = description;
}
public WelcomeViewModel()
{
}
}
The ViewModel.Welcome object is created and initialised with the data passed to it and remains so until control passes the SetContent method but when AddTab is called the WelcomeViewModel constructor seems to be invoked again and the data is reset. The call stack traces this to the
base.OnCreate(bundle);
call in the BaseTabbedView class. How do I keep hold of the data in the WelcomeViewModel so that it is displayed in my tab, Many Thanks
I have a feeling this is probably a bug I fixed a couple of weeks ago.
The bug was that the cache used for storing these child viewmodels was starting its indexing at 0 – and 0 was also being treated as the empty value by the Android Intent.
In vnext, see this checkin https://github.com/slodge/MvvmCross/commit/bcebadffee3850857d6a73070704e72b3aa72bcb
In master, see https://github.com/slodge/MvvmCross/commit/c3171e27168bf2b7e48dd73d105f5a08870cec5a