【问题标题】:Passing an enum as an argument in caliburn micro's action在 caliburn micro 的操作中传递枚举作为参数
【发布时间】:2012-10-17 12:14:24
【问题描述】:

如何在消息操作中传递枚举?例如,

XAML:

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

视图模型:

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

}

public enum LogicArrowEnum
{
    ARROW = 1,
    ASSIGN = 2,
    IF = 3,
    IF_ELSE = 4
}

【问题讨论】:

  • 您可以将 Menu 绑定到 MenuItem 的集合,MenuItem 将具有 Name 和 ArrowType 属性。

标签: c# .net wpf caliburn.micro


【解决方案1】:

你只需要传递Enum value as a string:

<MenuItem Header="Arrow" cal:Message.Attach="ChangeArrowType('ARROW')"/>

【讨论】:

  • 谢谢,应该记录在案。
  • 当时可能不是,但在今天是。只是为了未来的读者,寻找枚举值章节here
猜你喜欢
  • 1970-01-01
  • 2012-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-24
  • 1970-01-01
  • 2011-07-18
相关资源
最近更新 更多