Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WithConversion<...> does not appear do the same as WithConversion(new ...) #2449

Closed
1 of 7 tasks
tofutim opened this issue Dec 8, 2017 · 1 comment
Closed
1 of 7 tasks
Assignees
Labels
s/needs-more-info Needs more information from the reporter

Comments

@tofutim
Copy link
Contributor

tofutim commented Dec 8, 2017

Steps to reproduce 📜

  1. Write a new converter, I needed a NotValueConverter, so I wrote
public class NotValueConverter : IMvxValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return !((bool)value);
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return !((bool)value);
    }
}
  1. In my viewController,
set.Bind(loginButton).For(v => v.Enabled).To(vm => vm.IsLoggedIn).WithConversion<NotValueConverter>();

Expected behavior 🤔

When IsLoggedIn is false, I expect my loginButton to be enabled; which I guess means that I expect that MvvmCross will automatically look for the NotValueConverter, create an instance if it doesn't yet exist, and then use that.

Actual behavior 🐛

loginButton is not enabled, not converter is never called. However, if I use

set.Bind(loginButton).For(v => v.Enabled).To(vm => vm.IsLoggedIn).WithConversion(new NotValueConverter());

it does do the right thing. Maybe I had to Mvx.Register the NotConverter? Not sure. I also want to note that I can use .WithConversion("NotConverter") if I register using

protected override void FillValueConverters(MvvmCross.Platform.Converters.IMvxValueConverterRegistry registry)
{
    base.FillValueConverters(registry);

    registry.AddOrOverwrite("NotConverter", new NotValueConverter());
}

When I register as such, .WithConversion<NotValueConverter>() still does not work.

Configuration 🔧

Version: 5.5.2

Platform:

  • 📱 iOS
  • 🤖 Android
  • 🏁 WPF
  • 🌎 UWP
  • 🍎 MacOS
  • 📺 tvOS
  • 🐒 Xamarin.Forms
@mvanbeusekom
Copy link
Contributor

mvanbeusekom commented Dec 22, 2017

@tofutim sorry for the delay in response, its been a busy few weeks for me. Anyway I found some time to look into it and I am having a hard time on reproducing the problem.

I have created a reproduction example on my own GitHub fork which can be found here: https://github.com/mvanbeusekom/MvvmCross (in the issues/2449_GenericValueConverter branch). The example are part of the Playground.iOS and Playground.Mac test projects and can be found in the RootView class in both projects. I haven't done any additional registration to get the value converters to work.

First I created a simple converter which randomly gets a color and applied the color to a label (on both iOS and MacOS application) and both work fine using the generic WithConversion<RandomColorValueConverter> method.

After that (just to be thourough) I have also added a copy of your NotValueConverter to the Playground.Mac project and applied it to the Enabled property of the "Show Child" button in the RootView class. This also seems to behave as expected (you'll manually need to change the boolean value for the IsLoggedIn property of the RootViewModel class to see both states, but both work as expected).

Maybe you can have a look at these example implementations to check for differences in your solution. If you still experience the problem please provide a minimal reproduction example we can use to further debug this issue.

@mvanbeusekom mvanbeusekom added the s/needs-more-info Needs more information from the reporter label Dec 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s/needs-more-info Needs more information from the reporter
Development

No branches or pull requests

3 participants