<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://devlicio.us/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Christopher Bennage : Caliburn, viewmodel</title><link>http://devlicio.us/blogs/christopher_bennage/archive/tags/Caliburn/viewmodel/default.aspx</link><description>Tags: Caliburn, viewmodel</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><item><title>Things I’d Like To Present</title><link>http://devlicio.us/blogs/christopher_bennage/archive/2010/01/08/things-i-d-like-to-present.aspx</link><pubDate>Fri, 08 Jan 2010 11:32:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:54940</guid><dc:creator>Christopher Bennage</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;In case you are not familiar with &lt;a href="http://visitmix.com/" target="_blank"&gt;MIX&lt;/a&gt;, it is a conference from Microsoft focusing on the collaboration of design and development. Admittedly, the sessions tend to favor the developer, but there is always excellent design and UX content.&lt;/p&gt;  &lt;p&gt;&lt;a title="voting for MIX sessions" href="http://visitmix.com/opencallvote/?query=Christopher%20Bennage" target="_blank"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;margin-left:0px;border-top:0px;margin-right:0px;border-right:0px;" title="Mix10_Vote_grn_240" border="0" alt="Mix10_Vote_grn_240" align="right" src="http://devlicious.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/christopher_5F00_bennage/Mix10_5F00_Vote_5F00_grn_5F00_240_5F00_44742D31.jpg" width="184" height="244" /&gt;&lt;/a&gt; There was an open call for presentations this year and the community gets to choose which of the proposals will be selected. There are a number of &lt;a href="http://visitmix.com/opencallvote/" target="_blank"&gt;excellent proposals&lt;/a&gt; and I encourage you to go check out the list and vote for the sessions that you are genuinely interested in. (Even if you won’t be attending, the sessions will be broadcast.)&lt;/p&gt;  &lt;p&gt;Here are some sessions that I proposed for MIX10:&lt;/p&gt;  &lt;h3&gt;Cross Compiling Games for Silverlight &amp;amp; XNA&lt;/h3&gt;  &lt;p&gt;Our friend and Silverlight MVP, &lt;a href="http://blogs.silverarcade.com/silverlight-games-101/" target="_blank"&gt;Bill Reiss&lt;/a&gt;, has created an incredible library that enables you to cross compile XNA games for Silverlight. The library is called &lt;a title="a library for cross compiling XNA and Silverlight games" href="http://silversprite.codeplex.com/" target="_blank"&gt;SilverSprite&lt;/a&gt; and we feature it on Silver Arcade. (Wow, that’s a lot of ‘silvers’ in one paragraph.)&lt;/p&gt;  &lt;p&gt;In this session, we’d write a simple game for XNA (discussing some of the basic of game dev along the way) and then port the game over to Silverlight.&lt;/p&gt;  &lt;p&gt;This is an area where I wish I could spend more time. I love game development, but it’s always taking a back burner to other projects.   &lt;br /&gt;&lt;a title="Cross Compiling Games for Silverlight &amp;amp; XNA" href="http://visitmix.com/opencallvote/Entry?entryId=CROSSC046" target="_blank"&gt;[vote for this]&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;LinqToSQL and EntityFramework Profilers: Case Study&lt;/h3&gt;  &lt;p&gt;If you aren’t already familiar with the UberProf suite of ORM profilers, you can read tales of the development on &lt;a href="http://ayende.com/Blog/category/561.aspx" target="_blank"&gt;Ayende’s blog&lt;/a&gt;. Rob and I built the UI side of the application, and we learned a lot in the process. I’d like to do a talk were we discuss the challenges of the project, how we solved them, and what we did wrong. &lt;/p&gt;  &lt;p&gt;Yes, NHProf will be included too. (I submitted a case study for it last year, and it didn’t get picked. I have to sneak it in).&amp;#160; &lt;/p&gt;  &lt;p&gt;A few interesting aspects: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;we built this using MVVM, but well before &lt;a href="http://www.codeplex.com/caliburn" target="_blank"&gt;Caliburn&lt;/a&gt; reached maturity. &lt;/li&gt;    &lt;li&gt;the four separate apps (NHProf, EFProf, L2SProf, HProf) all use a single code base.&lt;/li&gt;    &lt;li&gt;we’re about to port the project from WPF to Silverlight.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a title="LinqToSQL and EntityFramework Profilers: Case Study" href="http://visitmix.com/opencallvote/Entry?entryId=LINQTO047" target="_blank"&gt;[vote for this]&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;Silver Arcade: Case Study&lt;/h3&gt;  &lt;p&gt;This is a presentation that Rob and I have made a couple of times. Most recently at the Orlando .NET Users Group. We walk through the actual code for &lt;a href="http://www.silverarcade.com" target="_blank"&gt;Silver Arcade&lt;/a&gt; explaining the philosophy, design choices and mistakes we made along the way.&lt;/p&gt;  &lt;p&gt;For MIX, we would focus more design and UX choices, such as the separation of the behaviors from the views. However, we like to have a lot of audience interaction and tend to follow where ever the questions led (especially those leading questions that &lt;a href="http://scottdensmore.typepad.com/" target="_blank"&gt;Scott Densmore&lt;/a&gt; tends to ask). &lt;/p&gt;  &lt;p&gt;Silver Arcade is also interesting because&amp;#160; we deliberately used a number of newer hipper technologies; including Azure, ASP.NET MVC, jQuery, MEF, NHibernate and so on.   &lt;br /&gt; &lt;a title="case study of Silver Arcade" href="http://visitmix.com/opencallvote/Entry?entryId=SILVER048" target="_blank"&gt;[vote for this]&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=54940" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/christopher_bennage/archive/tags/WPF/default.aspx">WPF</category><category domain="http://devlicio.us/blogs/christopher_bennage/archive/tags/Game+Development/default.aspx">Game Development</category><category domain="http://devlicio.us/blogs/christopher_bennage/archive/tags/fun/default.aspx">fun</category><category domain="http://devlicio.us/blogs/christopher_bennage/archive/tags/XNA/default.aspx">XNA</category><category domain="http://devlicio.us/blogs/christopher_bennage/archive/tags/Software+Architecture/default.aspx">Software Architecture</category><category domain="http://devlicio.us/blogs/christopher_bennage/archive/tags/web/default.aspx">web</category><category domain="http://devlicio.us/blogs/christopher_bennage/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://devlicio.us/blogs/christopher_bennage/archive/tags/MVC/default.aspx">MVC</category><category domain="http://devlicio.us/blogs/christopher_bennage/archive/tags/Presentations/default.aspx">Presentations</category><category domain="http://devlicio.us/blogs/christopher_bennage/archive/tags/UI/default.aspx">UI</category><category domain="http://devlicio.us/blogs/christopher_bennage/archive/tags/UI+Patterns/default.aspx">UI Patterns</category><category domain="http://devlicio.us/blogs/christopher_bennage/archive/tags/XAML/default.aspx">XAML</category><category domain="http://devlicio.us/blogs/christopher_bennage/archive/tags/UX/default.aspx">UX</category><category domain="http://devlicio.us/blogs/christopher_bennage/archive/tags/Caliburn/default.aspx">Caliburn</category><category domain="http://devlicio.us/blogs/christopher_bennage/archive/tags/viewmodel/default.aspx">viewmodel</category><category domain="http://devlicio.us/blogs/christopher_bennage/archive/tags/mvvm/default.aspx">mvvm</category></item><item><title>Caliburn Hello World</title><link>http://devlicio.us/blogs/christopher_bennage/archive/2009/11/22/caliburn-hello-world.aspx</link><pubDate>Sun, 22 Nov 2009 16:32:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:53989</guid><dc:creator>Christopher Bennage</dc:creator><slash:comments>3</slash:comments><description>&lt;p&gt;A friend recently complained to me that he had a hard time putting together a Hello World application using Caliburn. Here’s a simple step-by-step guide to getting a &lt;em&gt;very&lt;/em&gt; simple Caliburn application up and running with the 1.0 release.&lt;/p&gt;  &lt;p&gt;The goal is to demonstrate the built-in conventions-based binding for view models and views, as well as binding to a method on the view model. This tutorials assume a basic knowledge of &lt;a title="Model-View-ViewModel" href="http://en.wikipedia.org/wiki/Model_View_ViewModel"&gt;MVVM&lt;/a&gt;.&lt;/p&gt;  &lt;h3&gt;Setup&lt;/h3&gt;  &lt;p&gt;First, go and download the &lt;a href="http://caliburn.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=34985"&gt;1.0 RTW&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Next, we’ll create a new Silverlight 3.0 application. I&amp;#160; named mine HelloCaliburn.&lt;/p&gt;  &lt;p&gt;We’ll need to reference a few assemblies from the 1.0 RTW. Since we are working with Silverlight, the required assemblies are located in the downloaded zip at&lt;/p&gt;  &lt;p&gt;\Caliburn v1 RTW\Bin\Silverlight-3.0\release&lt;/p&gt;  &lt;p&gt;Since we are keeping things as simple as possible, we only need three assemblies:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Caliburn.Core.dll &lt;/li&gt;    &lt;li&gt;Caliburn.PresentationFramework.dll &lt;/li&gt;    &lt;li&gt;Microsoft.Practices.ServiceLocation.dll &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Copy these to a convenient location and add a reference to them in your Silverlight project.&lt;/p&gt;  &lt;p&gt;Next, we’ll create two folders in our project:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Views &lt;/li&gt;    &lt;li&gt;ViewModels &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Finally, I’ll delete MainPage.xaml, since we won’t be using it.&lt;/p&gt;  &lt;p&gt;The project looks like this:&lt;/p&gt;  &lt;p&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;margin-left:0px;border-left-width:0px;margin-right:0px;" title="the project setup" border="0" alt="the project setup" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/christopher_5F00_bennage/image_5F00_57E69F45.png" width="278" height="388" /&gt; &lt;/p&gt;  &lt;h3&gt;Caliburn’s Pattern&lt;/h3&gt;  &lt;p&gt;Caliburn has a opinion about how you should structure your application. (Of course, you can pick and choose and modify that default opinion considerably).&lt;/p&gt;  &lt;p&gt;By default, though, Caliburn thinks of the UI as a&lt;em&gt; graph or tree of view model objects&lt;/em&gt;. So we’ll need to have a top level view model that will be the root of this object graph. It’s become our common practice to name this root ShellViewModel.&lt;/p&gt;  &lt;p&gt;Let’s create a class ShellViewModel in the ViewModels folder. For the time being, we’ll leave it as a simple &lt;a title="Plain Ol&amp;#39; CLR Object" href="http://en.wikipedia.org/wiki/Plain_Old_CLR_Object"&gt;POCO&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;We’ll also need to create view that will be associated with the view model. Let’s create a new &lt;em&gt;Silverlight User Control&lt;/em&gt; named ShellView in the Views folder.&lt;/p&gt;  &lt;p&gt;The names ShellViewModel and ShellView are very important. Caliburn uses these names to associate a view with a particular view model. Given a view model named MyViewModel, Caliburn’s default convention is to look for a view named MyView. In addition, it expects the view models to be in a folder (or namespace rather) named ViewModels and that the corresponding views will in Views. All of these defaults can be changed.&lt;/p&gt;  &lt;h3&gt;Configuration&lt;/h3&gt;  &lt;p&gt;We are going to keep things to a bare minimum. We’ll inherit from the base class CaliburnApplication. This class will provide most of the default configuration we need. Open App.xaml.cs and modify it so that it looks like this:&lt;/p&gt;  &lt;pre class="C#:nogutter:nocontrols" name="code"&gt;namespace HelloCaliburn
{
    using Caliburn.PresentationFramework.ApplicationModel;
    using ViewModels;

    public partial class App : CaliburnApplication
    {
        public App()
        {
            InitializeComponent();
        }

        protected override object CreateRootModel()
        {
            return new ShellViewModel();
        }
    }
}&lt;/pre&gt;

&lt;p&gt;The override CreateRootModel returns an instance that will be the root of our UI object graph. It’s analogous to setting the RootVisual for the application. However, you’ll notice that it returns an object and is not to limited returning an actual visual.&lt;/p&gt;

&lt;p&gt;This is because Caliburn is biased towards the view model. This method returns the view model; it is the responsibility of Caliburn to locate and display the corresponding view.&lt;/p&gt;

&lt;p&gt;Since we’ve changed the base class for App, we also need to modify the associated XAML. Let’s change App.xaml to look like this:&lt;/p&gt;

&lt;pre class="xml:nogutter:nocontrols" name="code"&gt;&amp;lt;am:CaliburnApplication 
    xmlns=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;
    xmlns:x=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;
    xmlns:am=&amp;quot;clr-namespace:Caliburn.PresentationFramework.ApplicationModel;assembly=Caliburn.PresentationFramework&amp;quot;
    x:Class=&amp;quot;HelloCaliburn.App&amp;quot;&amp;gt;
    &amp;lt;Application.Resources&amp;gt;
    &amp;lt;/Application.Resources&amp;gt;
&amp;lt;/am:CaliburnApplication&amp;gt;&lt;/pre&gt;

&lt;p&gt;If we run the application now, everything would work. However, we couldn’t tell because the view and view model are empty.&lt;/p&gt;

&lt;h3&gt;Bindings&lt;/h3&gt;

&lt;p&gt;Silverlight and WPF already have a rich data binding system. However, it is awkward for binding to methods. One of Caliburn’s core features is the ability to bind to methods on the view model.&lt;/p&gt;

&lt;p&gt;Let’s add a simple string property to our view model and a method that will change the property when it is executed.&lt;/p&gt;

&lt;p&gt;We’ll make ShellViewModel inherit from Caliburn’s PropertyChangedBase. This class is a basic implementation of INotifyPropertyChanged. Modify ShellViewModel so that it looks like this:&lt;/p&gt;

&lt;pre class="C#:nogutter:nocontrols" name="code"&gt;namespace HelloCaliburn.ViewModels
{
    using Caliburn.Core;

    public class ShellViewModel : PropertyChangedBase
    {
        private string _message;

        public ShellViewModel()
        {
            Message = &amp;quot;My First Message&amp;quot;;
        }

        public string Message
        {
            get { return _message; }
            set
            {
                _message = value;
                NotifyOfPropertyChange(&amp;quot;Message&amp;quot;);
            }
        }

        public void ChangeMessage()
        {
            Message = &amp;quot;Hello World&amp;quot;;
        }
    }
}&lt;/pre&gt;

&lt;p&gt;I give the Message property an initial value in the constructor. This is just so we’ll see something when it is first displayed.&lt;/p&gt;

&lt;p&gt;We’ll bind to Message using standard binding techniques. However, we’ll need to use a Caliburn attached property, Message.Attach. Change the markup in ShellView.xaml to look like this:&lt;/p&gt;

&lt;pre class="xml:nogutter:nocontrols" name="code"&gt;&amp;lt;UserControl x:Class=&amp;quot;HelloCaliburn.Views.ShellView&amp;quot;
             xmlns=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;
             xmlns:x=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;
             xmlns:pf=&amp;quot;clr-namespace:Caliburn.PresentationFramework;assembly=Caliburn.PresentationFramework&amp;quot;
             Width=&amp;quot;400&amp;quot;
             Height=&amp;quot;300&amp;quot;&amp;gt;
    &amp;lt;Grid x:Name=&amp;quot;LayoutRoot&amp;quot;
          Background=&amp;quot;White&amp;quot;&amp;gt;
        &amp;lt;StackPanel&amp;gt;
            &amp;lt;TextBlock Text=&amp;quot;{Binding Message}&amp;quot; /&amp;gt;
            &amp;lt;Button pf:Message.Attach=&amp;quot;ChangeMessage&amp;quot;
                    Content=&amp;quot;Click Me&amp;quot; /&amp;gt;
        &amp;lt;/StackPanel&amp;gt;
    &amp;lt;/Grid&amp;gt;
&amp;lt;/UserControl&amp;gt;&lt;/pre&gt;

&lt;p&gt;The simplest way to use Message.Attach is to specify the name of the method on the view model. This causes Caliburn to “bind” the invocation of that method to the button’s click event.&lt;/p&gt;

&lt;h3&gt;You’re Done&lt;/h3&gt;

&lt;p&gt;Run the app and click the button. This is (of course) a very trivial example, but I hope it gives you an idea of how things work. For more details, be sure to check out &lt;a href="http://caliburn.codeplex.com/documentation"&gt;the official documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/christopher_5F00_bennage/HelloCaliburn.zip"&gt;Download the code for this tutorial here&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=53989" width="1" height="1"&gt;</description><enclosure url="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Components.PostAttachments/00.00.05.39.89/HelloCaliburn.zip" length="84584" type="application/x-zip-compressed" /><category domain="http://devlicio.us/blogs/christopher_bennage/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://devlicio.us/blogs/christopher_bennage/archive/tags/XAML/default.aspx">XAML</category><category domain="http://devlicio.us/blogs/christopher_bennage/archive/tags/Caliburn/default.aspx">Caliburn</category><category domain="http://devlicio.us/blogs/christopher_bennage/archive/tags/viewmodel/default.aspx">viewmodel</category><category domain="http://devlicio.us/blogs/christopher_bennage/archive/tags/mvvm/default.aspx">mvvm</category></item></channel></rss>