My name is Edward Tanguay. I'm an American software and web developer living and working in Berlin, Germany.
8 hours ago: Here's a use-case for datapod format, recording human-readable data that later can be used as a datasource: http://is.gd/eSsLg @pholdings.
9 hours ago: "Subscriptions are available to U.S. addresses only." http://www.highlights.com another global economy #fail.
9 hours ago: "Subscriptions are available to U.S. addresses only." http://www.highlights.com another global #fail.
11 hours ago: My notes on podcast with author Aimee Bender's Lemoncake book, "a normal kid punished by expectations of giftedness": http://is.gd/eSsLg.
12 hours ago: Interesting: "one page per book": http://openlibrary.org/about.
12 hours ago: Another after-work 8K, did 5K in 23:33, getting cooler here as #berlin #marathon approaches: http://is.gd/eSp95.
yesterday: C# CODE EXAMPLE: Extension method for checking regex in one line: http://is.gd/eQzyg.
yesterday: New podcast source: "I don't want to put you to sleep, but I want to be as rich, and rewarding, and resident as a dream.":http://is.gd/eQrdC.
yesterday: An intense colin marshall interview with michael silverblatt on the art of interviewing & more: http://is.gd/eQqve (search for "blatt").
yesterday: The stackexchange site for wordpress is up: get your answers / establish your reputation @cottonr http://wordpress.stackexchange.com.
2 days ago: "I've always felt that any time you can use a tuple, you should use a struct.": http://is.gd/eQm9V.
SILVERLIGHT NOTES ON VIDEO created on Thursday, April 02, 2009 permalink
Notes On Video: Implementing Model-View-ViewModel in Silverlight
If you recognize the advantages of MVVM but still haven't grokked it yet, this is an excellent video which builds a silverlight project from the ground up to demonstrate every part of the MVVM pattern, no more and no less, also lots of talking about the key terms so that the get pounded in. I was working on a an MVVM exampleand couldn't figure out how to get the View connected to the ViewModel - this video was exactly what I needed, lots of talking about all the pieces going step by step through a Silverlight solution started from scratch, very nice.
 > > >  watch video here
Introduction
  1. The presenter is Tim Heuer, excellent, always to the point.
  2. Mvvm is becoming increasingly popular, yes.
  3. Mvvm is new to silverlight.
  4. FLASHCARD: What is confusing about these patterns?
What Is MVVM?
  1. The model is the typical data model, same as in MVC and MVP, the representation of your entities.
  2. View is the abstraction of your UI elements, users interact with them.
  3. The ViewModel is the "glue binding" to provide data to the view, it serves the view.
  4. Some people said that there should be no code in the view at all, only XAML, but some people say, because of the limitations of Silverlight, you might need to have code in the XAML.
  5. FLASHCARD: What is the difference between MVC / MVP and MVVM?
  6. FLASHCARD: What is hard about silverlight if you are a web developer?
  7. For all intents and purposes, silverlight is a winforms app (it's client-side).
What Is DataContext?
  1. Talks about how the datacontext pushes down to the elements below it.
  2. Datacontext is very flexible: easy to use mvvm and master/detail.
12:10 Begins Writing Code
  1. Going to do a small math testing program.
  2. Commands = actions.
  3. Program says if when you put in teh right answer if it is right, very simple.
  4. File, new, silverlight project, nice that he starts from a blank solution.
  5. shows how silverlight knows "where to start", it's in app.xaml.cs:
15:40 Makes Model
  1. In Model makes question.cs.
  2. Talks about doing a webservice perhaps but now we will have mock data.
  3. You need to allow the changing of data in the view to be changing the model (back and forth).
  4. Public class Question : INotifyPropertyChanged.
  5. Now the view will get the event "hey, the property changed".
  6. Does: private void RaisePropertyChanged(string property), calls it a "helper class" but it is just a method (what?) then calls it a "helper event".
  7. We are not concerned with properties Text and ActualAnswer (they won't change) so they just have standard get and set.
  8. Uses strings, not integers (user always types in a string).
  9. does a typical property definition first:
  10. then adds to set:
    RaisePropertyChanged("ProvidedAnswer");
  11. makes the same type of property for grade:
  12. then puts in the setter of the first one that both will change:
  13. "Your model needs to be pretty well defined for the designer to even start working on the view."
26:00 Makes ViewModel
  1. Ok this is where it gets interesting, the QuestionViewModel has a property that is an ObservableCollection.
  2. Adds two mode questions here.
30:10 Makes View
  1. The ViewModel is talking to the Model, now we need it to talk to the View.
  2. purists would say that this is the only code that should be in your view (and is true for this demo):
  3. Creates QuestionView.
  4. drops in a bunch of XAML:
  5. just puts in "binding" which is something that was confusing me, says that you usually put in "binding path=..." but it is just the basic binding here:
  6. so the variables just get their information from the main binding:
  7. The designer can now open this in expression blend and "go to town".
  8. So the view is just an ItemsControl (with ItemsSource) which is going to emit the questions, that's it.
  9. ViewModel and Model are testable without the View.
34:40 Makes the Main Page
  1. "now we have to use that view".
  2. Now in Page.xaml.
  3. Puts in the namespace.
  4. in the grid you say:
    <views:QuestionView x:Name="QuestionDataView"/>
  5. FLASHCARD: If you ran it now, why would you get a blank page?
  6. Now in Page.xaml.cs.
  7. nice: always use Page_Loaded to make sure everything is loaded by this point (purists say so):
  8. Creats a ViewModel object.
  9. Calls FetchQuestions on it.
  10. Then connects the DataContext to it.
  11. VERY nice, so I see the problem I was having, namely, I was setting the DataContext to the whole ModelView itself whereas Tim here is setting the DataContext to the collection of questions, nice:
  12. Goes back to view: datacontext is being set at view in a sense, so the ItemsControl simply binds to the collection.
  13. Good practice: be explicit (mode=TwoWay is the default but we specify it).
41:00 Runs the Application
  1. Sees questions, walks through code.
  2. Interesting: it is the lost focus event triggers INotifyPropertyChanged.
  3. Then by raising those events, the checkbox is checked because it picks up the values of the properties in that collection.
  4. Performance is good because the ObservableCollection helps us out.
  5. "we're not doing logic, we're just binding to that property".
  6. We have a zero-persistence model, if you had an entity model then you would have to write it back (Entity Framework has a method to do this automatically).
  7. This is a pretty true separation of model and user interface (but even Path=Text is coupling the two in a sense).
48:10 Commands
  1. But Grade Me button is going to use a command, nice.
  2. He has a Click attribute in the button since Silverlight doesn't have Command per se.
  3. So you have to use a workaround (in wpf you would do something like Command="...").
  4. FLASHCARD: How do we implement commands in silverlight?
  5. "We are going to be writing code in the view which is going to be problematic for the purists."
  6. interesting: Tim said " the datacontext of the view is the ViewModel" which was exactly the error I made in my code above, actually he technically should have said "the datacontext of the view is the observable collection in the ViewModel", oh wait, I take that back since now, in the button click, he actually does indeed set the DataContext as a QuestionViewModel class and not as a ObservableCollection in that class as he had in Page.xaml.cs, so why the discrepency here?:
  7. 54:00 very meaty part, explaining commanding in silverlight with a simple example.
  8. "we are basically wrapping the commanding pattern in an event handler in the view".
  9. "button_click is invoking a method off our viewmodel".
  10. We can still test grade answers without the user interface.
  11. Actually we should say "SubmitAnswers".
55:25 Wrap Up
  1. This is super basic 101 MVVM.
  2. MVVM is still open and being discussed, is new.
  3. Lends itself better to validation.
  4. You can download the full code, nice.
  5. Using the DataContext just "makes it preprepared for you".
  6. Tim's concern: is MVVM too complex for every solution? my answer: yes, without MVVM you can write quick apps like this example I made in WPF with LINQ using multiple nested Datagrids, super useful for a bangout app that edits a full SQL database (used Northwind in the example) via WPF, an hour or so and no headaches and your done, but MVVM is useful for apps that go beyond quick tools and need to have unit tests run after every change etc.
  7. MVVM will give you greater testability.