简体   繁体   中英

Object to string ValueConverter not getting invoked

I have defined a Value Converter in my PCL like this:

class EmployeeToStringValueConverter : MvxValueConverter<Employee, string>
{
    protected override string Convert(Employee value, Type targetType, object parameter, CultureInfo culture)
    {
        return value.ToString();
    }
}

And I'm using it in an Android .axml layout like this:

local:MvxBind="Text EmployeeToString(SearchResult)"

( SearchResult is defined in the ViewModel as a public Employee property)

But it is not working (meaning: if I put a breakpoint in the Converter call, it is never executed).

However, I've also defined the following converter:

public class NegateBoolValueConverter : MvxValueConverter<bool, bool>
{
    protected override bool Convert(bool value, Type targetType, object parameter, CultureInfo culture)
    {
        return !value;
    }
}

And I'm using it like so:

local:MvxBind="Enabled NegateBool(IsLoggedIn)"

( IsLoggedIn is a bool public property in the ViewModel)

And this works perfectly.. Any idea so as to what may be going on with the first one that's not working?

I believe you are missing a public access modifier on your converter

Changing

class EmployeeToStringValueConverter : MvxValueConverter<Employee, string>

to

public class EmployeeToStringValueConverter : MvxValueConverter<Employee, string>

should do the trick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM