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?
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.
Yes, we can define an enumeration inside a class. You can retrieve the values in an enumeration using the values() method.
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.
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.
To access a nested class/struct/enum in XAML, use +
as a separator.
<XamlElement Tag="{x:Static local:MyClass+EnumName.enumValue1}"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With