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

Stuck/not responding when using IMarkupExtension<BindingBase> #81

Open
jackie0100 opened this issue Apr 2, 2019 · 1 comment
Open

Comments

@jackie0100
Copy link

We just recently bought 2 licenses for LiveXaml but we have hit a huge wall/problem with our localization system which is critical enough to sadly make the plugin unusable. The whole app and phone become literally unresponsive if we try to use liveupdate and after a while shutdown and closes the debugger too. The code below is basically how we do the translation look up:

` public class LanguageStringExtension : IMarkupExtension
{
public string StringID { get; set; }

    public object ProvideValue(IServiceProvider serviceProvider)
    {
        return ProvideValue(serviceProvider);
    }

    BindingBase IMarkupExtension<BindingBase>.ProvideValue(IServiceProvider serviceProvider)
    {
        return new Binding
        {
            Mode = BindingMode.OneWay,
            Path = $"[{StringID}]",
            Source = LocalizedResources.instance,
        };
    }
}`

We access this class in xaml like this:

<Entry Placeholder="{local:LanguageString StringID={x:Static local:StringIDs.Username}}" HorizontalOptions="Fill" MinimumWidthRequest="10" Grid.Column="1" Grid.Row="1" Grid.ColumnSpan="2"/>

Localized resource is a singleton class with access to our translations in resx files.

@jackie0100
Copy link
Author

We have fixed this problem by slightly rewriting the class to the following:

    public class LanguageStringExtension : IMarkupExtension<BindingBase>
    {
        public string StringID { get; set; }

        object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
        {
            return ProvideValue(serviceProvider);
        }

        public BindingBase ProvideValue(IServiceProvider serviceProvider)
        {
            return new Binding
            {
                Mode = BindingMode.OneWay,
                Path = $"[{StringID}]",
                Source = LocalizedResources.instance,
            };
        }
    }

not sure why this work but the above doesn't, just wanted to give a headsup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant