BESUG, Silverlight, WCF RIA Services, MVVM, Presentations and sessions »

[4 May 2010 | 0 Comments]

As mentioned in my previous post, my BESUG session on Model-View-ViewModel in Silverlight was recorded.  Well, today, it was posted at Channel 9!

 

For those of you who want to listen to my session, these are the links (att: in Dutch):

 

http://channel9.msdn.com/posts/adebruyn/Demystifying-MVVM--Part-1-Recording-BESUG-session/

http://channel9.msdn.com/posts/adebruyn/Demystifying-MVVM--Part-2-Recording-BESUG-session/

 

Have fun! :)

General, MVVM, Silverlight, WCF RIA Services »

[30 Apr 2010 | 0 Comments]

Thanks to everyone who attended my session on MVVM at BESUG yesterday (and thanks for the nice comments ;-))!  As promised, you can find the slidedeck and code here.

 

Included: Powerpoint slides, completed solution and DB Backup. 

 

What you need to run this: Visual Studio 2010 & Silverlight 4 (which includes WCF RIA Services).  For the database, you’ll need SQL Server 2008. 

 

    1. Restore the DB Backup
    2. Change the connection string in web.config
    3. Build, run & play with the code :-)

Hope to see you guys soon at some other event!  If you’ve got any questions on this, don’t hesitate to contact me.

 

Note: this session was also recorded and it scheduled to appear on Microsoft Chopsticks.  Once it’s been published, I’ll post the link.

Silverlight, WCF RIA Services, MVVM »

[22 Apr 2010 | 4 Comments]

As promised, here is the content from my Demystifying MVVM session @ Techdays Portugal.  For those who weren’t there, there’s a lot of stuff in this demo code:

 

  • MVVM base classes,
  • Connecting VM’s to V, using the Locator pattern
  • Connecting them using MEF
  • Unit Testing
  • MEF & Mocking
  • Command implementations (regular & generic), CommandTriggerAction
  • App wide messaging
  • Auto IsDirty support with WCF RIA Services
  • IDialogService implementation for showing Dialogs the MVVM way (same principle applies for your own navigation, states, animations, …)
  • … and some more stuff.

 

So: have a look at the code, and start MVVM-ing yourself in mintues! ;-)

Silverlight, General, Presentations and sessions »

[20 Apr 2010 | 0 Comments]

Just a quick reminder: Maarten Balliauw and I will be speaking at Techdays 2010 in Portugal this Thursday (that is, if our flight isn’t cancelled due to the ash cloud). 

 

We’ll be doing one session together: PHP + Silverlight, on how to get those two techs working together.  Maarten will be doing a session on PHP & his Azure SDK for it, Just another Wordpress blog, but more Cloudy , and I will be doing a session called Demystifying MVVM, on the Model-View-ViewModel pattern in Silverlight.

 

You will be able to find both the Powerpoint & demo code for my session on this blog soon after the sessions!

 

Feel free to say hi if you see me running around somewhere :-)

Silverlight, General »

[19 Mar 2010 | 1 Comments]

The MIX2010 conference has ended, most of the attendees are back home and are looking back at an eventful conference – and Vegas is a pretty nice location :-)  In case you missed it, here are some of the more interesting links (disclaimer: personal selection :)) to have a look at:

 

 

 

 

Oh by the way, you can expect more Windows Phone content coming up on this blog in the next few months – I’m going to be a Microsoft trainer for early adopters of Windows Phone 7 Series, so naturally, I will be developing for it quite a bit myself, and I fully intend to share some of my experiences on this blog! :)

General, Silverlight »

[11 Mar 2010 | 0 Comments]

The most important conference for .NET (web) developers of the year is coming up: MIX10, again in Las Vegas this year, from March 15th to 17th.

 

This is the first year I’m going, and I’m really looking forward to it (staying at the Mandalay Bay Hotel, as most of the attendees :-)).  I’m pretty sure we’ll hear all about how Silverlight 4 / WCF RIA Services is coming along, but I’m even more excited about the Window Phone, especially since it’s now known we’ll be able to develop applications for Windows Mobile using Silverlight – absolutely one of the best decision Microsoft could make as far as I’m concerned.  I, for one, am already looking forward to developing a few apps for the new Windows Phone :)

 

Next to that, I’m also looking forward to meeting a few people I’m following on Twitter – socializing is of course an integral part of a conference like MIX.  ;-) If Wifi allows it, I’ll check my Twitter account regularly – feel free to send me a message if you want to go for a beer!

 

… and of course, as this will be the first time in Vegas for me, I’m pretty excited about experiencing what Sin City has to offer! ;-)

 

Only one thing I’m absolutely NOT looking forward to is the long, long travel time: a bit more than 20 hours from Belgium, to be exact.  No fun at all for a smoker on a non-smoking airplane.  One positive aspect though: if I find a power slot on the plane, I might be able to finish a few blog post drafts for the coming weeks :)

 

Anyway, excited to meet people, excited to be in Las Vegas, excited to attend MIX10!  See you in Vegas?

 

MVVM, Silverlight »

[26 Feb 2010 | 1 Comments]

One of the more common problems (or rather: challenges :)) you’ll run in to when working with the MVVM design pattern is binding from a DataTemplate of an ItemsControl to a command defined on your ViewModel.  For example: you might have a ListBox filled with items, and you want a button in every ListBox item which, on click, should execute a command (delete the item, for example).

 

When you look around the internet, you’ll find a few possible solutions to this problem.  One “easy” one is to simply define a command in each item of the collection you’re binding the ListBox to: as each ListBox item’s DataContext is exactly one item, each DataContext contains a command, so you can bind to it.  Needless to say, this is not the way to go (do you really want a separate command, or a reference to a common command, in each ListBox item?).

 

Another common solution (and a much better one) is using RelativeSource bindings.  You can find a few posts on that on the Silverlight forum and on CodeProject.  As you might notice while looking for info on that: it used to be a WPF-only feature, but it is now supported in Silverlight.  You can find the MSDN page on it here.

 

While that works, there’s actually a much, much easier solution: Element Binding.

 

Take this piece of code:

 

  1. <ItemsControl ItemsSource="{Binding MenuItems}" Grid.Column="1" >
  2.             <ItemsControl.ItemsPanel>
  3.                 <ItemsPanelTemplate>
  4.                     <StackPanel Orientation="Horizontal"></StackPanel>
  5.                 </ItemsPanelTemplate>
  6.             </ItemsControl.ItemsPanel>
  7.             <ItemsControl.ItemTemplate>
  8.                 <DataTemplate>
  9.                     <Button Width="50" Height="50" Content="{Binding Label}"
  10.                             Margin="15">
  11.                         <ToolTipService.ToolTip>
  12.                             <TextBlock Text="{Binding Description}"></TextBlock>
  13.                         </ToolTipService.ToolTip>
  14.                             <i:Interaction.Triggers>
  15.                                 <i:EventTrigger EventName="Click">
  16.                                     <rdmvvm:CommandTriggerAction
  17.                                         Command="{Binding DataContext.ShowView, ElementName=LayoutRoot}"
  18.                                         CommandParameter="{Binding Uri}" />
  19.                                 </i:EventTrigger>
  20.                         </i:Interaction.Triggers>
  21.                     </Button>
  22.                 </DataTemplate>
  23.             </ItemsControl.ItemTemplate>
  24.         </ItemsControl>

 

This is from a project I’m currently working on: the MenuViewModel defines a command, ShowView, which accepts a parameter (the Uri a button click should navigate to).  The menu consists of a (variable, depending on the profile of who logs in) list of buttons, which is created by binding a list of MenuItems to an ItemsControl defined on the View. 

 

So, how do you get the button click event bound to the command defined on your ViewModel?  All my views have a root Grid, LayoutRoot.  As the Views’ DataContext is the ViewModel, the DataContext of LayoutRoot is that same ViewModel – which contains the defined command.  Through element binding, I can now easily bind the command to my ListBox Item, as you can see in the provided code example.

 

I can’t share the complete code this time (that would require sharing most of the internal libraries for MVVM etc we’re using, and would probably violate numerous NDA’s/intellectual property rights :)), but I hope the code sample I provided helps some of you out. 

 

Happy coding! :)