简体   繁体   English

具有多个 static class 的常量,用于 Xaml 属性

[英]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.但是,我无法将多个 static 类作为 Xaml 属性访问。

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}我尝试了几种变体,但我不能指定任何超过{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.我很乐意更改常量 class 的格式。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM