Jules
Jules

Reputation: 7774

Constants with multiple static class for Xaml properties

I've generated some constants from images files in our project. However, I'm having trouble accessing multiple static classes as a Xaml property.

Cannot resolve type "Constants.Images.Icons.IcAccount.Svg". (XFC0000)

namespace Common
{
    public static class Constants
    {
        public static class Images
        {
            public static class Icons
            {
                public static class IcAccount
                {
                    public static readonly string Svg = "res:images.icons.ic_account";
                    public static readonly string File = "ic_account.svg";
                }
<?xml version="1.0" encoding="UTF-8" ?>
<ContentPage
  x:Class="myapp.Pages.ActiveBookingPage"
  xmlns="http://xamarin.com/schemas/2014/forms"
  xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
  xmlns:control="clr-namespace:myapp.Controls;assembly=myapp"
  xmlns:common="clr-namespace:myapp.Common;assembly=myapp">

    <ContentPage.Content>
        <control:CustomImageButton
            ButtonImage="{x:Static common:Constants.Images.Icons.IcAccount.Svg}"

I've tried several variations however I can't specify any more than {x:Static common:Constants.Svg}

I found this as an initial basis, but it doesn't use multiple classes.

I’d be happy to change the format of my constants class.

Upvotes: 0

Views: 217

Answers (1)

DrkDeveloper
DrkDeveloper

Reputation: 949

The compiler does some clever stuff to manage nested classes, renaming it with the full class-tree with "+".

Use

common:Constants+Images+Icons+IcAccount.Svg

Upvotes: 2

Related Questions