views:

12

answers:

1

I have the following enum that represent a state of UI (I use it to enable and disable UI elements):

enum Mode 
{
 EDIT, RUN, REVIEW
}

I would like to pass Mode.EDIT to command in CommandParam:

  <Button Grid.Column="6" VerticalAlignment="Top Command="{Binding Path=ChangeMode}" 
CommandParameter="{StaticResource local:Mode.RUN}" />

But I have no idea how to declare it. As you see in the button declaration, I try to use StaticResource but it fails. I am quite new to SL4 and C# so I suppose that I missed something.

A: 

I have found a solution. I have created in my MyViewModel (my DataContext) 3 public attributes (of type Mode) and initialize them in the constructor (with values EDIT, RUN, REVIEW). Next, I have bound them in XAML as a normal property of a DataContext: CommandParameter="{Binding Path=EDIT}.

class MyViewModel
{

  public Mode EDIT {set; get;}
  public Mode RUN {set; get;}
  public Mode REVIEW {set; get;}

  MyViewModel()
 { 
   EDIT = Mode.EDIT;
    ...
 }
} 
Skarab