I am used to get the TextField using getViewById() to apply native android filters to it. How can I do this from ViewModel without breaking the rules of the MVVM architecture?
You cannot access the TextField from the ViewModel without breaking the MVVM pattern.
Anyway, I would advice you to just call getViewById() from ViewModel to set native android filter functionality, since the MVVM implementation of NativeScript is not designated solving this problem. You doesn't have to fear that this is bad practice at all.
Related
I hope there is a way for either SAPUI5 or OpenUI5 as this would ease the development efforts to implement data loss protection. If there isn't, I would be interested to know the best alternative to implement similar behavior. I was thinking of maybe extending the sap.f.routing.Router and checking an application-level dirty flag before handling the navigation.
Before exiting the application, methods:
https://sapui5.hana.ondemand.com/1.71.38/#/api/sap.ui.core.Component/methods/onWindowBeforeUnload and https://sapui5.hana.ondemand.com/1.71.38/#/api/sap.ui.core.Component/methods/onWindowUnload
are worked out in the Сomponent of the application. In this method, you can call the hasPendingChanges method on the OData model to check for unsaved changes and show a dialog for user interaction.
You can also look in the direction of drafts, implemented on the BOPF or RAP frameworks. Then the state will be stored on the backend. But this is a global change of concept, which will affect the revision of the implementation of logic in the backend.
Recently , I was confusing about Rxbinding and Databinding for my project.
Basically , my project is applying MVVM architecture.
However there was some screen is created with Databinding and other one is worked with RxBinding.
I am considering to do refactor code and apply all with Databinding.
In fact, in some case Rxbinding is a best way to implement (Of course databinding also can use for this case) so I do not want to change.
To be honest, there was some usecase that is very difficult to implement by Databinding concept.
My question:
Base on the concept of MVVM architecture, View should not has data or logic and just observe data from ViewModel to update immediately its changes.
So, what is the essential difference between Rxbinding and Databinding ?
When should I use Rxbinding and when Databinding?
Background:
We're using Caliburn.Micro 3.0.0-beta2 with a WPF + Xamarin iOS / Android project and we want to ensure the view models can be cross platform to reuse as much code as possible.
We've been looking at how to abstract our our navigation to be testable, cross platform and so callable in the view model rather than the views.
I was wondering if anyone had suggestions about how we should handle our app navigation. Our screens require us to inject some data such as database ID's into screens as we're navigating around. Currently we've done this with a view first approach by injecting the data into the view and having that pass it into the view model, but this doesn't feel ideal as it should really go into the view model as it's view logic (right?).
The view model is created for the view view using ViewModelLocator.LocateForView(this); and this then satisfies the rest of our dependencies using the SimpleContainer.
We Understand that navigation hasn't been implemented into 3.0.0 yet according to https://github.com/Caliburn-Micro/Caliburn.Micro/issues/142. We're really looking for a way we could do navigation that may be similar to the Caliburn.Micro solution implemented soon, with a hopeful view to contribute towards this if possible.
Questions:
How would we go about getting the data into the view model rather than the view to make it easier to test and more similar to how our WPF application will need to work?
Is this even sensible for a mobile app or should we be taking a view first approach? If so, what would be a testable approach for this?
Unless you have setup Caliburn.Micro for view-first approach (can be done there is a sample for this) the framework is almost completely viewmodel first in nature. I find it rather difficult to work in view first. Most of my "screens" are developed around the view model in question. With that in mind I also at times have multiple views for each viewmodel depending on the operation (add/ edit/ details/ list) for example.
1) DI, usually through repository or other context of that nature then using BindableColllection to hold and notify of changes to the view. Pretty much the same as WPF would work. Most recently my code has started to be cross platform (WP to WPF, now more Universal) to help reduce my headaches. Most of the patterns used are DI(SimpleContainer), Repository (EF 6x), Pub/Sub (IEventAggregator). The one exception is Repository but to an extent I still use it on WP but since I use Sqlite, up until recently EF was out of the question (EF 7 to the rescue)...
2) Do what is comfortable. If you are use to using Fakes then do it. It shouldn't matter as long as you have the correct results you are looking for in the end. Of course I am sure each test is going to be slightly tweaked for the platform they are tested on. Since each platform has its own nuances that you have to take into account.
I am loving MvvmCross so far, but I am new to the MVVM technique. MVVM seems to center around the View and ViewModel and navigating between them. However, what about application-wide model items? Maybe my application has a mode that it can be in that affects all views and viewmodel behavior. This seems like an ApplicationModel or ApplicationViewModel. Or maybe just use the App class itself to store application wide stuff? What is the recommended practice for this concept? If using the App class itself is a good idea, I assume there is an easy way to get a hold of the reference to the App instance from anywhere? Haven't looked yet.
A ViewModel is a Model for a View - so that's where the current MvvmCross focus sits.
For this application wide behaviour, I think it's best to consider it one use case at a time.
The example you've provided is:
Maybe my application has a mode that it can be in that affects all views and viewmodel behavior.
There's not much detail here, but for this type of thing I might perhaps:
place this Mode inside a Singleton service
would use a messenger to send ModeChangedMessages when the Mode changed
would provide that service and the messenger to the relevant ViewModels using constructor injection
the ViewModels can then subscribe for ModeChangedMessage on the messenger
would perhaps use inheritance in my ViewModels to share code between them (ie they'd inherit from a BaseViewModel class)
There are of course other ways to do this, but that's one suggestion
If there's some other application wide use case you'd like to ask about, please ask another question - but please include more detail - eg perhaps provide some pseudo-code about what you want to share. I find real use cases easier to work out - abstract ideas are harder to talk about.
If it helps:
There's an introduction to services and constructor injection in N=2 on http://mvvmcross.wordpress.com
There's an introduction to the Messenger on N=9 in http://mvvmcross.wordpress.com
Looking into various MVVM frameworks for SL. In the Caliburn documentation I saw a code in a controller that calls MessageBox. Is this right or is this just for intro? Is there something like MessageBox service in Caliburn like in Chinch MVVM?
It's indeed introductive code, just to demonstrate that the controller method is actually executed. Yet, I agree on the issue you pointed out: the presence of raw UI code in the presenter could lead to an inappropriate mix of view concerns.
About the MessageBox service: in Caliburn v2 (trunk), ShellFramework module, there is a Question/Answer ViewModel abstracting the functionality of a MessageBox, with the advantage of letting you to design the UI for the dialog.
Also, it's very straightforward to roll your own IMessageBox abstraction and provide a basic implementation using the default WPF MessageBox.
Marco is correct. This is just to demonstrate that the action is called. I wouldn't recommend this in practice. I will try to make some changes to the samples or add some comments that make this clearer. Caliburn has services built-in for calling custom message boxes.