Reputation: 5618
Particularly the Navigation between the Views over the ViewModels looks like that:
ShowViewModel<InfoViewModel>();
Or between normal Activities:
context.StartActivity(typeof(InfoActivity));
The problem I face now (actually I solved it in one of my latest projects by using Tinymessenger - its an event aggregator/messenger for loosely coupled communication) but I would like to know if theres an other way!
I'm creating an optionsmenu:
public abstract class BaseActivityWithoutTabs<T> : MvxActivity where T : class, IMvxViewModel
{
public override bool OnCreateOptionsMenu(IMenu menu)
{
return ActivitiesHelper.CreateOptionsMenu(menu);
}
public override bool OnOptionsItemSelected(IMenuItem item)
{
return ActivitiesHelper.CreateOnOptionsItemSelectedEvent(item, this);
}
}
InfoActivity
derives from this BaseActivityWithoutTabs
.
In the ActivitiesHelper Class (from above code) I'm creating the menu and the events:
public class ActivitiesHelper
{
private const int einstellungenItemId = 0;
private const int infoItemId = 1;
public static bool CreateOptionsMenu(IMenu menu)
{
// GroupId, ItemId, OrderId
menu.Add(0, einstellungenItemId, 0, "Einstellungen").SetIcon(Android.Resource.Drawable.IcMenuManage);
menu.Add(0, infoItemId, 1, "Info").SetIcon(Android.Resource.Drawable.IcMenuInfoDetails);
return true;
}
public static bool CreateOnOptionsItemSelectedEvent(IMenuItem item, Context context)
{
var id = item.ItemId + 1; // (Id is zero-based :)
if (id == 1) // First Item
{
context.StartActivity(typeof(SettingsShowActivity));
}
else if (id == 2) // Second Item
{
context.StartActivity(typeof(InfoActivity)); //doesn't work...
}
return true;
}
}
As you see I do here "StartActivity
".. it works for the first "SettingsShowActivity
" but thats an PreferenceActivity, so there no reason why it should fail. The problem is, that I would like to Start here the InfoActivity
(as you see in code - Second Item) and this doesn't work. It opens the Activity but the List doesn't gets filled.
But if I go to a ViewModel in my project and call: ShowViewModel<InfoViewModel>();
it works fine but this is on that place (in the ActivitiesHelper Class) not available/possible!
public class InfoViewModel : MvxViewModel
{
public InfoViewModel()
{
Info info = new Info();
info.Key = "ITS A KEYY";
info.Value = "here we got a value";
ObservableCollection<Info> asd = new ObservableCollection<Info>();
asd.Add(info);
Infos = asd;
}
private ObservableCollection<Info> infos = new ObservableCollection<Info>();
public ObservableCollection<Info> Infos
{
get
{
return infos;
}
set
{
infos = value;
RaisePropertyChanged(() => Infos);
}
}
}
Any suggestions?
Upvotes: 0
Views: 1362
Reputation: 66882
I have no idea what you are talking about. Seriously, you've just dumped a lot of stuff on the screen.
I think you've gotten yourself very confused - good luck trying to work out what on earth you've done.
One basic answer is that you can navigate to an Mvx-based Activity anywhere you want to simply by:
MvxViewModelRequest
- https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross/ViewModels/MvxViewModelRequest.csIntent
using the IMvxAndroidViewModelRequestTranslator
singleton - https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Droid/Views/IMvxAndroidViewModelRequestTranslator.csIntent
However, I seriously suggest you step out of your current mess and consider a cleaner application flow.
Upvotes: 2