Wednesday, June 18, 2008

Nihkil wrote sometime ago about ‘actions’, which was a concept he created that attach some behavior to elements. Think of the action of pressing the ‘enter’ key in a textbutton and executing some logic (sparing the user a click on the button next to the textbutton).

He has clearly been thinking more about his framework and now posts about the MVC concept of the ViewModel, extending it with his actions here. Good write-up. Go read it.

Basically, he explains what a ViewModel is and shows how to execute ‘command’-like behavior on them. As you might know, Silverlight does not support the concepts of commands, like WPF does. His syntax is like this:

 

  1 <vm:View xmlns="..." xmlns:x="..."
  2   xmlns:vm="clr-namespace:Silverlight.FX.ViewModel;assembly=Silverlight.FX"
  3   xmlns:app="clr-namespace:AmazonSearch.Views">
  4   <vm:View.Model>
  5     <app:SearchViewModel />
  6   </vm:View.Model>
  7 
  8   <Grid>
  9     <TextBox x:Name="searchTextBox" />
 10     <Button Content="Search" IsEnabled="{Binding CanSearch}">
 11       <vm:ButtonEvents.Click>
 12         <vm:InvokeMethod MethodName="Search">
 13           <vm:ElementParameter ElementName="searchTextBox" ElementProperty="Text" />
 14         </vm:InvokeMethod>
 15       </vm:ButtonEvents.Click>
 16     </Button>
 17 
 18     <ItemsControl ItemsSource="{Binding Products}">
 19       <ItemsControl.ItemTemplate> 
 20         <DataTemplate><app:ProductView /></DataTemplate>
 21       </ItemsControl.ItemTemplate>
 22     </ItemsControl>
 23   </Grid>
 24 </vm:View>
25

The thing to note is in lines 10 to 15. There he invokes a method straight on the ViewModel.

The concept is quite the same as the Caliburn project from Rob and the idea is very powerful!
It enables you to have no code-behind and go straight to the viewmodel. Very nice!

Thinking about this a bit though, does make me wonder if the added Xaml is worth the ability to go straight to the viewmodel. Wouldn't it be just as simple to define a Search method on the codebehind and invoke the correct method in the viewmodel?

My point being: is it worth to incorporate such a framework (albeit very small and succinct). What do you think?

Wednesday, February 17, 2010 10:43:07 AM (Romance Standard Time, UTC+01:00)
Good morning. I bookmarked this guestbook. Thank you for good job. Help me! Can not find sites on the: Land rover discovery for sale. I found only this - <a href="http://www.justiceplanbook.com/Members/Discovery">rides discovery</a>. Article marketing is a laden collaboration to prevent when it offers to agreeing time to your expedition, discovery. Fiendishly, in the potassium of bacterioferritin and ferritin, the equipment teeth are once farther however and only get to take rna brochure, discovery. With best wishes ;-), Troy from Luxembourg.
Tuesday, August 31, 2010 8:45:20 AM (Romance Standard Time, UTC+01:00)
welcome to http://www.kissmbtshoes.com discount mbt shoes
and look forward to your best choice for mbt shoes.
Go into http://www.wedding-dresses-mall.com look forward to you choice for wedding dresses and http://www.brand-watch-supplier.com/power-balance-c-49/ power balance
http://www.brand-watch-supplier.com/raymond-weil-watches-c-45/ Raymond Weil Watches
http://www.brand-watch-supplier.com/omega-seamaster-c-46/ Omega Seamaster
http://www.brand-watch-supplier.com/rolex-oyster-perpetual-c-47/ Rolex Oyster Perpetual
The best and beauty model of dresses.
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):