Simple case:
<usercontrol>
<Views:UserListView x:Name="settingsTreeView"/>
<Button DataContext="{Binding ElementName=settingsTreeView, Path=SelectedItem}"
Command="{Binding CreateChildCommand}"/>
</usercontrol>
The task just is to bind to button a DataContext which implements CreateChildCommand. DataContext is the selected item in the treeview. Nothing to happen. I have checked the button properties at run time: both Command and DataContext properties of the button are null.
Questions:
- Is it valid to change DataContext at runtime?
- How to pass selected item to the Command object?
Concerning commanding in Silverlight you can refer to:
http://johnpapa.net/silverlight/5-simple-steps-to-commanding-in-silverlight/ http://community.infragistics.com/silverlight/media/p/125526.aspx
http://houseofbilz.com/archives/2009/05/22/adventures-in-mvvm-commands-in-silverlight/ http://www.silverlightshow.net/items/Silverlight-4-How-to-Command-Control.aspx
something goes wrong