Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Constants in xaml

Tags:

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?

like image 582
Flack Avatar asked Oct 12 '10 21:10

Flack


1 Answers

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.

like image 159
ASanch Avatar answered Oct 14 '22 12:10

ASanch