I currently have a project in Xamarin and I am using MvvmCross. I have an MvxActionBarActivity that hosts MvxFragments. Now when I want to close the entire MvxActionBarActivity, the event begins in the Fragment and I want to tell the MvxActionBarActivity to close. Calling Close(this) in the fragment viewmodel is not working.
I have considered using MvxMessegner to send message from one viewmodel to the other but due to the relationship of a fragment and an activity I am wondering if there is a better way to do this.
Any help would be much appreciated.
Thank you!
When you want to close an Activity you need to call Finish(). This will close that activity and go back to that what is on the backstack.
If you want to call that from your viewmodel you should use a custom presenter: http://gregshackles.com/presenters-in-mvvmcross-navigating-android-with-fragments/
Related
I have read the two other questions on SO regarding this and I wanted to know if there is a good solution for that now / best practice.
Long story short, we use an SDK which is written natively and we've wrapped it so that it works on Xamarin.Android and Xamarin.iOS. It has asynchronous callback methods. I need to call a method in the shared code when a callback is received in the Android project for instance.
There's a lot of info for doing the opposite - using DependencyService. How about in my scenario? Does anyone have experience with an app like this and what's the best approach to keep code clean and do this using MVVM?
The options I know are:
Using a static App instance - this is what we currently do.
MessagingCenter
Anything else?
Actually I've never seen anyone recommend usage of MessagingCenter for anything else than communication between ViewModels so I am not sure it is recommended here. Also, I need to know the sender object type so I need a reference to the class in the platform specific project.
I would recommend you to use messagingCenter to pass data or call method between shared project and platform project. You can just send a new object instead of the class in the platform specific project.
Also, have a look at using eventhandler as I mentioned in this answer may help someone who want to call from the shared project into the platform specific one.
BTW, I mean you can even pass an object as TSender if it is not necessary to use:
MessagingCenter.Send<Object>(new object(), "Hi");
MessagingCenter.Subscribe<Object>(new object(), "Hi", (sender) =>
{
// Do something whenever the "Hi" message is received
});
Not found PushPopupPageAsync
_navigationService.PushPopupPageAsync( "MyPopupPage" );
I am using Rg.Plugin.Popup along withg Prism
but PushPopupPageAsync not available on INavigationService
how to solve it?
Are you sure that you should be calling PushPopupPageAsync? Rg.Plugin.Popup extends the Navigation service with PushPopupAsync - note there is no Page in the name.
To be able to use PushPopupAsync you also need to have:
using Rg.Plugins.Popup.Extensions;
in the source file where you want to call PushPopupAsync
Its easier to use the Prism.Plugin.Popups made by the Prism maintainer, then you can just use the standard NavigateAsync method:
_navigationService.NavigateAsync("MyPopupPage")
With this, te page is pushed as a popup with Rg.Plugin.Popup. (of course you have to target a PopupPage to make this works)
I want to create a dialog utility unity that could be called in an asynchronous way from different threads and show my dialog message on the active form, and I was sure that TDialogServiceAsync was the perfect way to do it but I can't call the MessageDialog method from outside the Main UI Thread.
Is it possible to achieve what I want without having to actually create a method in my main form that shows the dialog?
I'm developing for Windows right now but a method that could work on multiple plataforms would be appreciated.
Thanks in advance.
no, everything that touch the ui must be done in the main ui thread (quite logic). the only think you can do in your background thread
TThread.queue(nil,
procedure
begin
showdialog...
end);
I want to show AlertDialog(DisplayAlert) in a Xamarin.Forms project when an unhandled error occurs.
How can I get the current page instance?
You need to keep a reference of your main page as you mentioned. There are a few ways to do this.
You can have a static reference to it in your App.cs file, which is actually already there as it inherits from Application which has:
App.Current.MainPage
If you use an MVVM helper like MVVMLight you pass the page to the service so it keeps a reference of it.
ACR UserDialogs is a dialog package that can also help as it extends and adds different types of dialogs
To get around this and have a lot more flexibility add 'ACR User Dialogs' package to each of your platform's projects.
Then you can use that from anywhere :
await UserDialogs.Instance.AlertAsync ("Your question has been successfully sent", "Thankyou");
I'm writing a plugin for an application and need to use Carbon to show a dialog. I have everything set up including the event handler, but I cannot possibly call RunApplicationEventLoop() because this would stall the host application.
How can I fix this? Will I need to create a separate thread and call RunApplicationEventLoop() from there?
-Joe
What makes you think you need to call RunApplicationEventLoop? The host app is presumably running an event loop, probably either using RunApplicationEventLoop or NSApplicationMain. By the way, would your dialog be modal? Modal is easier.