Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you assign an enum, nested in a class, to a XAML attribute?

Normally, when I assign an enum value to a XAML attribute (usually the "Tag"), I use:

<XamlElement Tag="{x:Static local:EnumName.EnumValue}"/> 

Now, I have an enum defined inside of a class. e.g.:

public class MyClass{     public enum MyEnum {         enumValue1,         enumValue2     } } 

I try to assign this in XAML as:

<XamlElement Tag="{x:Static local:MyClass.EnumName.enumValue1}"/> 

and it doesn't work.

Can anyone tell me the correct way to accomplish this?

like image 577
Sako73 Avatar asked Jul 21 '11 20:07

Sako73


People also ask

How do I assign an Enum value to another?

Internally however Enums are simply integers. So you can easily assign one to the other by casting to integers. Or you directly cast the value to the type of the other Enum to indicate the compiler that you know what you are doing.

Can I declare Enum in class?

Yes, we can define an enumeration inside a class. You can retrieve the values in an enumeration using the values() method.

Can we assign variable to Enum?

You can assign different values to enum member. A change in the default value of an enum member will automatically assign incremental values to the other members sequentially.

How do you declare an enumeration?

The keyword 'enum' is used to declare new enumeration types in C and C++. Following is an example of enum declaration. // The name of enumeration is "flag" and the constant // are the values of the flag.


1 Answers

To access a nested class/struct/enum in XAML, use + as a separator.

<XamlElement Tag="{x:Static local:MyClass+EnumName.enumValue1}"/> 
like image 123
Julien Lebosquain Avatar answered Oct 22 '22 01:10

Julien Lebosquain