Constants in xaml

血红的双手。 提交于 2020-05-11 04:03:27

问题


Let's say I have a class defined something like the below:

namespace MyProject.MyConstants
{
    public class Constants
    {
        public class Group1Constants
        {
            public const string DoIt= "DoIt";
        }
    }
}

I am trying to use this const, from a separate project, in my xaml. I included the namespace:

xmlns:constants="clr-namespace:MyProject.MyConstants;assembly=MyProject.MyConstants"

and am trying to use the constant as follows:

<MenuItem Header="{x:Static controls:Constants.Group1Constants.DoIt}">

The above wont compile though, saying that

Cannot find the type 'Constants.Group1Constants'. Note that type names are case sensitive.

I must be missing something simple. All I want to do is use some constants from a class in different project in my xaml.

Any suggestions?


回答1:


Try this one:

<MenuItem Header="{x:Static constants:Constants+Group1Constants.DoIt}">

I used "+" instead of "." to reference the nested class. Not sure if you'll run into problems doing this though.



来源:https://stackoverflow.com/questions/3919012/constants-in-xaml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!