Passing an enum as an argument in caliburn micro's action
Asked Answered
T

1

5

How do I pass in an enum inside a message action? for instance,

XAML:

<UserControl.ContextMenu>
    <ContextMenu StaysOpen="True">
        <MenuItem Header="Arrow"
                  cal:Message.Attach="ChangeArrowType(LogicArrowEnum.ARROW)"/>
     ....

ViewModel:

public void ChangeArrowType(LogicArrowEnum arrowType)
{
    MessageBox.Show(arrowType); //arrowType is empty!

}

public enum LogicArrowEnum
{
    ARROW = 1,
    ASSIGN = 2,
    IF = 3,
    IF_ELSE = 4
}
Tyler answered 17/10, 2012 at 12:14 Comment(1)
You could bind the Menu to a collection of MenuItems, MenuItem would have a Name and ArrowType property.Eccrine
M
15

You just need to pass the Enum value as a string:

<MenuItem Header="Arrow" cal:Message.Attach="ChangeArrowType('ARROW')"/>
Metaphrase answered 21/10, 2012 at 6:24 Comment(1)
probably it was not at that time, but as of today it is. Just for future readers, look for Enum values chapter hereInnuendo

© 2022 - 2024 — McMap. All rights reserved.