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

Vai1212Vai1212 Member ✭✭
edited March 2018 in Xamarin.Forms

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>


`

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

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

  • Vai1212Vai1212 Member ✭✭
    edited March 2018

    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

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    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/

  • Vai1212Vai1212 Member ✭✭

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

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    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.

Sign In or Register to comment.