damirarh / damirscorner-utterances

utteranc.es comments for https://damirscorner.com
0 stars 0 forks source link

/blog/posts/20140217-CreatingConvertersInMvvmCross.html #5

Open damirarh opened 1 year ago

damirarh commented 1 year ago

Imported

URL: https://www.damirscorner.com/blog/posts/20140217-CreatingConvertersInMvvmCross.html

damirarh commented 1 year ago

Imported comment written by Rainzo on 2016-11-05T17:57:11

If I may ask, how would these converter public properties be set on an android project or iOS project?

damirarh commented 1 year ago

Imported comment written by Damir Arh on 2016-11-09T03:06:38

It's been a while since I've last used MvvmCross, but I think you will need to manually register the converters as shown in the documentation: https://github.com/MvvmCros...

I didn't test it, but the following should work:


protected override FillValueConverters(IMvxValueConverterRegistry registry)
{
base.FillValueConverters(registry);
var onOffConverter = new BoolToTextConverter
{
TrueValue = "On",
FalseValue = "Off"
};
registry.AddOrOverwrite("OnOffConverter", onOffConverter);
}

That is, you create an instance of the converter with desired property values and manually register it with a custom name that you can use in bindings.

To simplify the code, you could add a parameterized constructor or factory method and call it instead of using the initializer syntax.

damirarh commented 1 year ago

Imported comment written by cassey swaine on 2017-07-04T07:49:40

Hi Rainzo, you can have a look here, explains how: https://www.casseykeating.c...