locked
Getting Exception : Xamarin.Forms.Xaml.XamlParseException: Cannot assign property "Text" RRS feed

  • Question

  • User366294 posted

    Hi All,

    I am Working on Multilingual functionality while i am binding my label with the Key , It is trowing Exception. Please help Me. `

    <ContentPage.Content>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="100" />
                <RowDefinition Height="120" />
                <RowDefinition Height="200" />
                <RowDefinition Height="77" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="30" />
                <ColumnDefinition Width="280" />
                <ColumnDefinition Width="50" />
            </Grid.ColumnDefinitions>
            <StackLayout Grid.Row="1" Orientation="Vertical" Grid.Column="1">
    
                <Label Text="{translator:Translate OneApp}" TextColor="#FEFEFE" Font="15" HorizontalOptions="Center" VerticalOptions="Center" HorizontalTextAlignment="Center"></Label>
            </StackLayout>
        </Grid>
    </ContentPage.Content>
    

    `

    Thursday, March 22, 2018 11:27 AM

All replies

  • User180523 posted

    Nothing to help with. You need to show us your markup pertaining to the Label throwing the error.

    Thursday, March 22, 2018 11:28 AM
  • User366294 posted

    XAML:

    Helper:

    [ContentProperty("Text")] public class TranslateExtension : IMarkupExtension { const string ResourceId = "xxx.Resources.AppResources"; static readonly Lazy resmgr = new Lazy(() => new ResourceManager(ResourceId, typeof(TranslateExtension).GetTypeInfo().Assembly)); public string Text = "";

        public object ProvideValue(IServiceProvider serviceProvider)
        {
            if (Text == "")
                return "";
    
            var ci = CrossMultilingual.Current.CurrentCultureInfo;
    
            var translation = resmgr.Value.GetString(Text, ci);
    
            if (translation == null)
            {
    

    if DEBUG

                throw new ArgumentException(
                    String.Format("Key '{0}' was not found in resources '{1}' for culture '{2}'.", Text, ResourceId, ci.Name),
                    "Text");
    

    else

                translation = Text; // returns the key, which GETS DISPLAYED TO THE USER
    

    endif

            }
            return translation;
    
        }
    }
    

    I am working of Current version of VS 2017 and i Choosed .Net Standard

    Thursday, March 22, 2018 11:30 AM
  • User180523 posted

    Please edit your post and fix the markdown around the code so the site parser doesn't eat it. Its impossible to follow the way it is. https://redpillxamarin.com/2016/12/13/faq-frequently-asked-questions/

    Thursday, March 22, 2018 11:42 AM
  • User366294 posted

    I have updated my Question. PLease have look and let me know

    Thursday, March 22, 2018 11:50 AM
  • User180523 posted

    You named your property Text? That's a really bad choice in names because its already a keyword. That would be like naming a property Page or int or Label

    Go back and apply to good naming conventions to your code and see if that UNconfuses the compiler. Its probably getting lost in which Text you're referring to.

    Please also fix your second post - I'm sure you can see how bad the formatting of the code is.

    Thursday, March 22, 2018 12:10 PM