views:

39

answers:

2

hi, i am working on this article here they are using Silverlight 4. link text

but i am using Silverlight 3.but for button we are not able to find the command

Command="{Binding Path=DataContext.GetPerson, ElementName= LayoutRoot }"

<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="53,112,0,0" Name="button1"
                VerticalAlignment="Top" Width="75"  Command="{Binding Path=DataContext.GetPerson, ElementName= LayoutRoot }" 
                    CommandParameter="{Binding Path=Age, ElementName=hi}"  />

so in Silverlight 3 what should i do to get this Command property for the button

any help would be great

A: 

A command is a bindable way of associating an action to a control (button for instance). The command controls 2 things:

  • whether it can be executed
  • what to do when it's executed

by implementing the ICommand interface

They've been around for a while in WPF and were recently added to SL4

If you want your code to work in SL3 you'll have to bind the IsEnabled property to a property in your view model that has the same logic as the CanExecute implementation of the command and to add a Click event handler for the button which has the same logic has the command's Execute

Also, this button passes a parameter to the command (CommandParameter), you'll have to handle passing this parameter manually

vc 74
A: 

You could use a framework like prism, add the relevant dll's to your project, then add a reference to the top of page like so

xmlns:prism="clr-namespace:Microsoft.Practices.Composite.Presentation.Commands;assembly=Microsoft.Practices.Composite.Presentation"

Then declare the prison attribute on your button

<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="53,112,0,0" Name="button1"
        VerticalAlignment="Top" Width="75"  Command="{Binding Path=DataContext.GetPerson, ElementName= LayoutRoot }" 
        prism:Click.Command={Binding SomeCommand}
        prism:Click.CommandParameter="{Binding Path=Age, ElementName=hi}"  />
Neil

related questions