Forum Cross Platform with Xamarin


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

How do I get rid of binding error using ResX/PCL with UWP?

Hi all,

I have a cross-platform (iOS, Android, UWP) solution that I have created a PCL called ApplicationResources that contains resource strings. I have it working fine but I get errors for any Xaml that references those strings because the strings are static properties created by PublicResXFileCodeGenerator. UWP does not seem to like to bind to static properties. The app compiles and runs fine but I would like to get ride of these errors.

I load reference to class that provides access to the strings in App.xaml merged dictionaries:

    <applicationResources:LocalizedStrings x:Key="Localization" />

LocalizedStrings looks like this. AppStrings is the auto-generated class.

namespace ApplicationResources
    public class LocalizedStrings
        public LocalizedStrings()

        public void RefreshCulture()
            var languageCultureName = CultureInfo.CurrentUICulture.Name;
            Debug.WriteLine($"RefreshCulture: languageQualifier = {languageCultureName}");
            AppStrings.Culture = new CultureInfo(languageCultureName);

        public AppStrings Strings { get; } = new AppStrings();

The xaml refernce looks like this:

<TextBlock Grid.Row="1" Text="{Binding, Source={StaticResource Localization}}" Margin="{StaticResource StandardTopMargin}"/>

The error is this:

ErrorXLS0518 Expected 'email' on type 'AppStrings' to be an instance member.

The error totally makes sense but don't know how to easily get rid of it.

I tried the approach mentioned at the bottom of this SO post but couldn't get it to build without errors:

Seems if I had a generator that created properties that were not static I wouldn't get these errors.

I'm wondering if you folks have an idea of how to do this in a better way or whether I should just ignore these errors.

I believe the idea for this approach originally came from @Cheesebaron .


Best Answer

  • TedRogersTedRogers USMember ✭✭✭✭
    Accepted Answer

    x:Bind now lets you bind to static properties:

    <TextBlock Text="{x:Bind ar:AppStrings.app_copyright}"/>


  • ColeXColeX Member, Xamarin Team Xamurai
    edited August 2018


    I think you can make AppStrings (not email inside it) be Static.


    Text="{Binding email, Source={x:Static local:LocalizedStrings.Strings}}"
  • TedRogersTedRogers USMember ✭✭✭✭

    @ColeX - x:Static does not exist in UWP.

  • TedRogersTedRogers USMember ✭✭✭✭
    Accepted Answer

    x:Bind now lets you bind to static properties:

    <TextBlock Text="{x:Bind ar:AppStrings.app_copyright}"/>

  • kinekine FIMember ✭✭

    @TedRogers I have exactly same problem, but I cannot bind to static properties with x:Bind either. Can you share some details how to get it working? Does it require some minimum version of Windows 10 SDK? Are you using VS2017 or VS2019? I am using VS2027, minimum version is 16299, target version 17763.

  • TedRogersTedRogers USMember ✭✭✭✭

    @kine I am using Visual Studio 2017. My minimum version is 16299 and target is 17763 as well.

    My resx resources that I am referencing are in a PCL. I have this "PublicResXFileCodeGenerator" specified as the Custom Tool for the resx.

    In top of my xaml, I have this line:


    Here is how I used it for some Text in my xaml:

    Text="{x:Bind ar:AppStrings.add_folder}"

    Sample project attached.


  • kinekine FIMember ✭✭

    @TedRogers Thanks for the details. In my project the error just disappeared at least for now. There were some unrelated errors in the same XAML and after I fixed those, also binding errors disappeared. So now it works without any code changes, I am using "Binding" still. I also upgraded to VS2019 and it still works. Quite strange...

Sign In or Register to comment.