Create a custom visibility converter

I am trying to create my own converter for my MvvmCross project. I inherit the MvxBaseVisibilityValueConverter and just implement the Convert method.

Do I need to implement platform-specific projects, or is there a way to reuse platform visibility plugins?

+4
source share
1 answer

I have documented ValueConverters in the last few days - see https://github.com/slodge/MvvmCross/wiki/Value-Converters

I just added this ValueConverter custom visibility example to the article:


If you need to create your own Visibility ValueConverter, then the base classes MvxBaseVisibilityValueConverter<T> and MvxBaseVisibilityValueConverter can help with this - for example:

 public class SayPleaseVisibilityValueConverter : MvxBaseVisibilityValueConverter<string> { protected override MvxVisibility Convert(string value, object parameter, CultureInfo culture) { return (value == "Please) ? MvxVisibility.Visible : MvxVisibility.Collapsed; } } 

Using this approach, the plugin base class converts MvxVisibility to a suitable eigenvalue at runtime - so you only need to add this class type to your main PCL project - you do not need to add your own versions of the class - instead, the base class from the plugin will take care of the MvxVisibility -> native Visibility conversion MvxVisibility -> native Visibility .


Except> in addition to the Visibility enum support from the Plugin, recent changes to the Tibet binding have also added custom Visible binding properties to all platforms - it's just a bool , which is much easier to use - they should only work on iOS and Android, but on on Windows platforms, they will only work if you switch to the Tibet mvx:Bi.nd binding style (so not everyone prefers the approach!)

+5
source

Source: https://habr.com/ru/post/1496372/


All Articles