MvvmCross - MonoGame - data-binding

I'm trying to build a MonoGame view inside MvvmCross on Android,iOS and WP8. On Windows side it's relatively easy to use dependency properties as a binding target, but how can I achieve a cross platform data binding solution that I can use on all platform?

This was covered in a previous MvvmCross version - see Insert a Monogame view inside MvvmCross monodroid Activity
The technical details have changes a bit since that post, but the core of the advice remains the same - use inheritance to add data-binding.
For example, if you want to adapt a FooActivity or FooViewController base class so that it can be used for MvvmCross data-binding, then you need to:
inherit from FooActivity to provide EventSourceFooActivity - to do this you need to add event notifications like those shown in MvxEventSourceFragmentActivity.cs
inherit from EventSourceFooActivity to provide BindingFooActivity - to do this you need to add all the members like DataContext from MvxFragmentActivity.cs
The process for Touch/iOS is very similar, but with iOS specific events and members. Take a look at any of the Mvx*ViewController classes to see what is involved.
This technique is also discussed in: Integrating Google Mobile Analytics with MVVMCross

Related

what approach to use a specific component that is only available for iOS or WPF or android in Xamarin Forms?

what approach is used to create a specific component that is only available for one platform?
Can I use Custom Renderer or DependencyService or any other approaches is there ?
If you want to set the UI desinger on a specific control or layout .Such as entry or button.You can use custom renderer.
Custom renderers provide a powerful approach for customizing the appearance and behavior of Xamarin.Forms controls. They can be used for small styling changes or sophisticated platform-specific layout and behavior customization. This article provides an introduction to custom renderers, and outlines the process for creating a custom renderer.
And you can use DependencyService if you
just want to call some native API .
DependencyService allows apps to call into platform-specific
functionality from shared code. This functionality enables
Xamarin.Forms apps to do anything that a native app can do.
And you can also use Effects.In some cases, all three can help you implement your requirements.
There are some relevant cases that use one of them to solve the issue.I hope they can help you better understand their differences and usage, and how to choose them as a solution in specific cases.
CustomRenderer case
DependencyService case
Effect case

Xamarin - MVVM Cross Data Binding Resources

I am starting a cross-platform project in Xamarin, and I have some doubts that are me to prevent development. Initially the project is only for android and UWP but in the near future it will be also for iOS.
Questions:
1. I want to centralize all resources (strings for labels like "Name", "Age") in order to be consumed in the 3 platforms and when you have to edit this string, the change is made on all projects. What better way to do this? I need to do DataBinding on UI in all plataforms
[Xamarin.Android] I researched and heard of anything like "MVVMCross" but this forces me to extend my activities other own the MVVMCross and for example, and uencessito to take Android one ActionBar and for that I need to extend a class that can extender "AppCompatActivity" being, however, can only extend an activity and that therefore can not extend the actitivties from the MVVMCross.
Video: https://youtu.be/_DHDMNB_IeY?list=PLR6WI6W1JdeYSXLbm58jwAKYT7RQR31-W
Like:
public abstract class BaseActivity: AppCompatActivity // (with MVVMCross use MvxAppCompatActivity )
public class MainActivity: BaseActivity // (with MVVMCross use MvxActivity)
   
For assets, the correct approach is to keep the assets in the project, and if they are common to pass the PCL? I ask this because the assets on Android, iOS and UWP, the dimensions are different. What is good practice?
Thanks in advance!
For string resources and translations located just in your PCL I would suggest to use this library (very simple to implement):
https://github.com/xleon/I18N-Portable/, but you can also try and implement Resx files from your PCL.
Adding MvvmCross to your project just for localization would be just crazy.
But if you already use MvvmCross in your project, there´s a plugin for translations that uses json files at the PCL level: https://github.com/MvvmCross/MvvmCross/wiki/MvvmCross-plugins#jsonlocalisation.
For question 2: You can embbed resources in your PCL and load them from platform projects (ios/android/etc), but it won´t be as obvious as loading platform resources (you´ll need additional code). Thus, your assets and images usually change across platorms (different resolutions, dpi and design style guides) so trying to put them all together may complicate things more than helping.
About using specific MvvmCross Activities: that´s the way it works.

Xamarin Forms Maps - Custom Pin Images

Is there a way to change the image of the pins in Xamarin Forms Maps. I want to make the pin a custom image, if it has to be done natively, can someone give me a simple example of it. Thank you.
To anyone coming to the later, this is now well supported in Xamarin Forms.
In essence you need to create a custom map class in your PCL or shared code that inherits from the Xamarin Forms Map and then create a Custom Renderer in each of the platforms' projects.
Those custom renderers will be different for each platform, dealing with the specifics of rendering icons and any pop up information shown when you click on that pin for that particular platform. You are not obliged to create a custom renderer for all platforms, for any that you don't a normal map will be displayed.
This is all now really well documented in the Custom Renderers | Customizing a Map section of the Xamarin Forms Developers Guide. That documentation walks through creating a custom renderer for Android, iOS and UWP and explains the code needed in detail. There's a lot of it, so I won't reproduce it here. There is also an accompanying sample solution here.
One point worth noting is that if you are trying to reproduce that code in your own project you will also need to add the images in the various drawable folders in the ProjectName\Droid\Resources directory, and also the two axml files in the layout directory.
Apparently this is quite locked down and you have to look at custom renderers to achieve what you are needing.
There is a discussion about this on the following link:-
http://forums.xamarin.com/discussion/17916/customization-of-xamarin-forms-maps-pins
, with specific reference to a project at the following link which someone has implemented custom image pins from the Assets folder:-
https://github.com/paulpatarinski/ShouldIWashMyCar/blob/master/Android/Renderers/MapViewRenderer.cs
I haven't tried this yet, however this would probably be a good place to start when looking to customize map rendering.
This project might be helpful to you. raechten/BindableMapTest
From the description:
Small sample for binding a collection to a Xamarin Forms Maps pins
(valid until binding directly to the Pins property will be supported
by Xamarin Forms directly).
Includes custom and clickable pins.
It has Android and iOS implementations.

Use of spark.core.SpriteVisualElement in a mobile application

The question is: Is it a good practice to use SpriteVisualElement instead of UIComponent to create custom components? The reason being I can't add Sprite or FlexSprite as direct children of View and I see that UIComponent is quite heavy then SpriteVisualComponent from code point of view.
I searched extensively to confirm if there are certain examples elsewhere which shows use of this control as the base to create custom controls but could only find this. So actually I was little less confident about weather this is Ok or not.
Below is the supplement information:
Nature of application: Educational game application for children
Target platform: Mobile device (currently only Android platform)
Application environment: Flex SDK4.6 with AIR 3.8. Blank Spark application with spark.components.ViewNavigator. PureMVC framework used. Multiple Views to contain custom components which mostly use graphics package to draw themselves and to draw child controls within them (This is where I actually extend SpriteVisualElement for custom drawing as well as containing and displaying other custom controls).
Please suggest me if what I am doing is a good practice for a mobile app or not.
Thanks in advance and regards,
Sachin.
I use it often as SpriteVisualElement is lighter. I always try to use lighter things if it's fit my needs so I think it's a good practice especially for mobile development.

should I move from caliburn to caliburn.micro

I'm developing an infrastructure for a major project currently based on caliburn 1.
It works fine but it seems like the future is in caliburn micro, am I right?
If I do, how do I implement filters? How do I specify view to a view viewnodel (non conventional)?
And whats the best place to put my splash logic (not root model)
I recommend moving to Caliburn.Micro as it's simpler and easier to extend. It is where any future innovations will be made and it has a larger more active community. As far as filters go, you can actually build them and plug them in. See here Marco's post You can add non-conventional view specification as well. You just plug into the view locator and teach it how to find views. For example, if you want to use an attribute, you can just have the locator look for that attribute first, use it if found, otherwise fall back to the default behavior. Regarding splash logic, you can do that by customizing the Bootstrapper.

Resources