Question

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.

Was it helpful?

Solution

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;
    ...
 }
} 

OTHER TIPS

In WPF we can do something like this (might not work in SL) -

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

check this question for more details - Passing an enum value as command parameter from XAML

in silverlight x:Static doesn't work so we can do sth like this:

<Button Command="{Binding Path=ChangeMode}">
    <Button.CommandParameter>
        <Mode>RUN</Mode>
    </Button.CommandParameter>
</Button>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top