2

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.

3 Answers 3

3

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; ... } } 
Sign up to request clarification or add additional context in comments.

Comments

3

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

Comments

1

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> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.