TriggerFirstNavigate() calls start() method of ViewModel before Show() method of presenter - xamarin

I have a scenario where I have LoginActivity with Fingerprint option.
When the app starts, I want fingerprint dialog to be shown. I start the fingerprint flow from Start() method of LoginViewModel but the activity instance is null since Show() is not yet called from presenter.
Please let me know if there is a way to fix this.

In MvvmCross, The ViewModel lifecycle is agnostic to any platform lifecycle.
If you need to do something when a particular event happens at UI level, you can use the View callbacks that MvxViewModel has. In this particular case, you can use ViewAppearing or ViewAppeared.
You can read more about this in the official documentation.

Related

Is there a simple way to auto register [Exports] in a Prism app? WPF .NET 4.8

I used to be on a project that used Prism and when we needed a new service to do something, we'd just create an interface, a concrete class that implemented that interface and exported it, and then it just became available everywhere for [ImportingConstructor]. We didn't need to manually register it or anything. I no longer have access to that project, but I don't think there was any reflection magic that was done manually to accomplish this.
I'm in a new company and we are starting up a project using MEF / Prism and I'm trying to accomplish the same thing, but as of right now, I'm having to manually register items in order to import them. What am I missing?
I'm in .NET 4.8 WPF app
Additional info
we are basing our project from this website
https://prismlibrary.com/index.html
This is our app class
public partial class App
{
protected override Window CreateShell()
{
return Container.Resolve<ShellWindow>();
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterSingleton<IStartupActionService, StartupActionService>();
containerRegistry.RegisterSingleton<IGeneralNavigationService, GeneralNavigationService>();
containerRegistry.RegisterSingleton<IExperimentSetupNavigationService, ExperimentSetupNavigationService>();
containerRegistry.RegisterSingleton<IProtocolSetupNavigationService, ProtocolSetupNavigationService>();
containerRegistry.RegisterSingleton<IOurProjectNavigationService, OurProjectNavigationService>();
containerRegistry.RegisterSingleton<IOurProjectUiService, OurProjectUiService>();
containerRegistry.RegisterManySingleton<WcfClientService>();
containerRegistry.RegisterSingleton<IControlClientService, ControlClientService>();
}
}
Why do I have to register each new service?
I've been reading about MEF, DryIoc, and others and I'm just not getting clear answers. Is there not a way to just have everything with an [Export] become immediately available for import?
Something else I need to do, that I think this whole registering thing is messing me up on is trying to come up with a way to have "dialogs" but tie them to a neutral class to make it more MVVM happy.
Dialog -> a region that pops open when you call a method. This method currently takes in a UserControl, assumed to have already been constructed and its ViewModel datacontext already attached.
What I would like to do and don't know how to start is
use a neutral container class to open one of these dialogs (similar to interaction request Notification
using attributes, attach an attribute to a view that indicates "I support this neutral container class" (assumed only one view per container)
this view supports [ImportingConstuctor] to bring in its ViewModel
the viewmodel itself supports [ImportingConstuctor] to bring in services needed
again, the desire to NOT need to register these items manually as we add them. Would like to add a service interface, the concrete class that [Export]s the interface and have it just available to the viewmodel and other services, and same for the views and viewmodels, export attribute tag them as necessary and have them just available to either/both grab an instance of them or manually create an instance of them and have their [ImportingConstructors] handled for me.

WKInterfaceButton simultaneous push segue and action

Why is it that when a WKInterfaceButton is connected to both a push segue and an action, the action isn't called?
When you perform a segue, the old InterfaceController goes off screen, of course. WatchOS seems to destroy the bridge between your extension and the App (the storyboard/interface). The same thing happens in the other direction. The extension can't modify UIs that aren't on screen. An example is UI properties. Try setting the color of a label after the interface controller goes off screen. It won't work.
From the docs:
Important
An interface controller can make changes to its interface only during initialization and when the interface is active. Once the didDeactivate() method is called, any attempts to change the value of related interface objects are ignored until the interface controller’s willActivate() method is called again.
Presumably you're an iOS dev. It might be good to read through https://developer.apple.com/reference/watchkit/wkinterfacecontroller
Since I started learning watchOS, a lot of my assumptions/experience did not translate well over to the watch.

Binding toolkit: GestureListener events to methods in view model

In a Windows Phone 7.5 project, is there a way to bind
<toolkit:GestureListener DoubleTap="GestureListener_DoubleTap"/>
directly to a view model method?
Sounds like you might need the EventToCommand behavior. Alternatively you could roll your own behaviors with touch event handler command properties or attached dependency properties of type ICommand that handle the events. Depending on preference.

Should events fire themselves?

I'm not a solid GUI programmer, so I'm trying to understand different event architectures. I'm developing a system (in GWT, but I'm not sure that matters) where we are introducing a few custom events. In general, is it good practice to create an event and have the event fire itself onto to the event bus?
Following some articles and tutorials online, we have our controller code actually firing the events, but then each controller has to duplicate the code to fire the custom event. It seems that if you just put a fire() method on the event itself you can avoid that duplication.
What are the pros/cons of doing this?
In order to have an event fire itself, you'd need to inject the EventBus instance into the event when you create it. This means your controller (the one newing up the event) would have:
new MyEvent(m_eventBus).fire();
If you rework the code like this:
MyEvent event = new MyEvent();
m_eventBus.fireEvent(event);
then you wouldn't have to put any logic or references to services inside your Event instance, where it's not really needed. If you're using GWT, the HandlerManager class already implements an event bus for you.

When does Application_Launching event fire?

I have been playing with the latest templates (patched for Beta tools) and application life cycle. When I was looking for a place to initialize the DispatchHelper, I noticed that the Application_Launching event handler was being executed AFTER the MainViewModel constructor has executed. Is this the expected behavior?
This entirely depends on how and when you are creating your MainViewModel. If you think about it Launching should not be executed until all static objects and the main application object have been fully constructed.
You many want to delay construction of the MainViewModel until after you know whether you have been launched or re-activated. Even better would be to delay construction of the view model until after you know which page you will be displaying.

Resources