I'm writing a mobile app using Xamarin and I have a static class called Strings that wraps my RESX resources. I want to use x:Static to bind to these in my XAML files. This is working if I have a single static class with static properties to bind to.
I'm cutting out some comments and other non-essential bits, but it basically looks like this:
namespace MyCompany.Resources
{
public static partial class Strings
{
public static string LabelUsername { get { return Resources.LabelUsername; } }
}
}
Then in my XAML, I bind to it like this:
<Entry Placeholder="{x:Static resources:Strings.LabelUsername}"
where resources is defined as
xmlns:resources="clr-namespace:MyCompany.Resources;assembly=MyCompany"
That all works fine. It breaks down when I add a nested class to Strings. The class looks like this:
namespace MyCompany.Resources
{
public static partial class Strings
{
public static partial class Label
{
public static string Username { get { return Resources.Label_Username; } }
}
}
}
If I do that, then I would bind to it in my XAML like this:
<Entry Placeholder="{x:Static resources:Strings.Label.Username}"
Notice how after "resources:" we now have three levels (Strings.Label.Username). This seems to be what fails. When I do this, I get the compile error: Type Strings.Label not found in xmlns clr-namespace:MyCompany.Resources;assembly=MyCompany
Also, I can access the nested class and its properties just fine from my ViewModels. Is there any way to make this work from the XAML? I know I could bind to a variable in the VM and then have that reference Strings.Label.Username, but I don't want to do that for every resource binding.