16.08.2012 Views

dotnetrocks 0638 rob eisenberg

dotnetrocks 0638 rob eisenberg

dotnetrocks 0638 rob eisenberg

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Rob Eisenberg: But each one them would have<br />

their own View and you would edit the View. So for a<br />

conductor you might create a View that was basically<br />

a tab control over a collection, but the ViewModel<br />

itself would be the conductor ViewModel that controls<br />

how that tab control actually works and hooks into the<br />

activating and deactivating of those different tabs.<br />

Richard Campbell: Right.<br />

Rob Eisenberg: So in Visual Studio you just<br />

see your View just like you normally would in the<br />

designer and you just have your ViewModel that<br />

would p<strong>rob</strong>ably inherit from like a conductor as a<br />

normal class and that just happens to be the class<br />

that encapsulates the behavior of that user interface<br />

and conducts it, if you will, through its paces.<br />

Richard Campbell: The main thing is that you’re<br />

basically picking a base class to work from and you<br />

go from there.<br />

Rob Eisenberg: Yes. As I said, it's a base class<br />

for the ViewModel, not for the View.<br />

Richard Campbell: Right.<br />

Rob Eisenberg: But it controls the behavior of<br />

the view.<br />

Richard Campbell: And do I understand there's<br />

some ability to build Win Phone 7.0 apps using<br />

Caliburn.Micro?<br />

Rob Eisenberg: Absolutely. Caliburn.Micro<br />

works on WPF, Silverlight, and Windows Phone 7,<br />

and one of the things that we did was try and bring as<br />

much of this workflow from Silverlight into the phone<br />

as we could and to go a little bit further to integrate<br />

with some other phones' specific features. So for<br />

example, if you build a Phone 7 app, you know that it<br />

sort of has a navigation paradigm built into it. Now<br />

what we do is we hook into that navigation paradigm<br />

and we do some neat things with that. The phone, via<br />

that navigation paradigm, is sort of a View-first<br />

approach because the phone itself is loading pages<br />

and there's no way to intercept that and sort of load<br />

the ViewModel first. So we work backwards and we<br />

connect things the other way. So if you load a certain<br />

page, we’ll then locate the ViewModel and then we'll<br />

bind them and we can apply all the same conventions<br />

that we do with Silverlight and WPF against your<br />

phone pages. We do some other neat things. One<br />

common thing with navigation in phone apps is that<br />

you would navigate to a page and have some query<br />

string parameters.<br />

Richard Campbell: Right.<br />

Rob Eisenberg MVVMs Us with Caliburn.Micro!<br />

February 17, 2011<br />

Rob Eisenberg: So we take those query string<br />

parameters, we parse them out and we look at your<br />

ViewModel and we see if you’ve got any properties<br />

with the same names as those parameters, and if you<br />

do we'll coerce, type coerce, the values and push<br />

them in into those properties. So you never need to<br />

worry about how am I getting that parameter string,<br />

that query string information into my ViewModel. As<br />

part of that navigation note that we do, we push those<br />

things in there. The other thing, a couple of neat<br />

things we do, is there’s a real p<strong>rob</strong>lem with doing<br />

ViewModels against the app bar in the phone<br />

because the app bar is actually mostly implemented<br />

in native code with a very thin wrap on top of it so it<br />

doesn't support data binding or behaviors or any of<br />

the things you would typically use. But because our<br />

binder is applying all these conventions, one of the<br />

things it does is it inspects the View to see if it has an<br />

app bar, and if it does we do a little bit of extra work<br />

behind the scenes so that we can take all the features<br />

of actions and apply them into the app bar, to the app<br />

bar buttons and app bar menus.<br />

Richard Campbell: That's clever.<br />

Rob Eisenberg: So you get a very simple, very<br />

seamless experience. You don't really have to<br />

change the way you deal with the app bar versus the<br />

way you would deal with other buttons throughout<br />

your app and so on and so forth.<br />

Richard Campbell: It just sounds like we're close<br />

to an idea where you could actually build a chunk of<br />

code that ran fairly well in both the phone and on the<br />

web.<br />

Rob Eisenberg: Fairly well. But the main thing<br />

is going to be that basically the outer shell of the app,<br />

because the phone is really using that navigation<br />

framework and from that point in the architecture it's<br />

going View-first and have a very explicit way that the<br />

phone expects to run your app, you have to take that<br />

into account. But with inside of each individual page,<br />

that can be identical across the platforms for the most<br />

part.<br />

Richard Campbell: Like you'd almost build a<br />

framework onto the web side of things that would<br />

support that behavior, maybe a little different<br />

interpretation so you use the screen better and use a<br />

paradigm that's more web-centric. But you got me<br />

thinking now, Rob. There are some interesting ideas<br />

here about getting to that nirvana of write once, run<br />

across the platforms.<br />

Rob Eisenberg: Well, the main thing for me is,<br />

it’s not even the differences between the technologies<br />

but starting with WPF back in -- I don't know when I<br />

started, 2005 or 2006, developing a sort of<br />

methodology and a way of thinking about solving and<br />

Transcription by PWOP Productions, http://www.pwop.com Page 11 of 13

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!