Mike Taulty's Blog
Bits and Bytes from Microsoft UK
Blend Bits 17–Coding in Blend

Blogs

Mike Taulty's Blog

Elsewhere

Archives

Blend seems to have been a little schizophrenic with regard to whether it wants you to write code inside the environment or not.

Going from memory I think version 1 had a code editor and then 2 took it out and 3 might have put it back and beefed it up and 4 definitely still has one.

Generally, I’d say that it’s best not to code in Blend if you’re wanting to write a lot of code but it’s fine if you just need to write a little bit of something and, also, I’d say that there are some things in there that I’d like to see Visual Studio add.

If you’re writing event handler code then it’s worth remembering that the properties window has an events tab which I’ve tried to highlight below;

image

and you can type in the name of an event handler into one of those boxes and hit return and Blend will create that event handler for you (of the right shape) and drop you into the code editor for that event handler as in;

image

Now, if you’re anything like me this view of code will make you feel very itchy because it’s simply not big enough and there’s a bunch of things getting in your way.

Remain calm and hit either the F4 or the TAB key to take all the panels away;

image

and it’ll feel a little like a place that you can get some work done. There are also a few options as to how your code is displayed but not too many;

image

This is not Visual Studio.

The other thing to say is that the code environment does have IntelliSense and does some statement completion so for instance if my cursor is at this point indicated;

image

then hitting CTRL+SPACE will bring up the IntelliSense;

image

and continuing to select a function and attempt to call it will do a similar thing when I hit the opening brace;

image

What Blend doesn’t do which I find a bit limiting is provide any facility whereby it assists me in trying to figure out what namespace a particular class that I know about is in so if I have referenced System.Xml.Linq and I type code;

image

then as far as I know there’s no way to get Blend to help me out by telling me that XElement is in the namespace System.Xml.Linq. I have to know that.

The other thing I’d say is that adding references in Blend is not so easy.

When you go and add a reference to the project via;

image

What you’re confronted with is the standard Windows file dialog;

image

which is about as much use as a chocolate tea-pot as they say around these parts. What I really want is a dialog that presents me with the standard Silverlight assemblies, the SDK assemblies, the toolkit assemblies.

Here’s my top tip for this. If you’re on Windows 7 then create yourself a library;

image

Here’s an example of the folders you might set up;

image

and then in that dialog inside of Blend I can pretty easily find the assembly that I’m trying to reference and search for it;

image

The other aspect of coding in Blend (where I feel it wins over Visual Studio in some respects) is the “Add New Item” dialog.

Let’s compare and contrast;

image

image

Hmmm…ok. Now where Blend wins for me here is in offering me little templates for Action, Trigger and Behavior and UserControl with ViewModel.

To be fair, Action and friends kind of “belong” to Blend so I can see why Visual Studio doesn’t have templates for them but I’m always forgetting which base class I’m meant to use for these things so I like the fact that Blend tries to help me along with it.

So, it’s reasonable to write a little bit of code in Blend and there’s a bunch of work gone into supporting you on that. I have to admit though that once I’ve gone a certain way and written more than (say) 10 lines of code, I do often find myself wanting some of that VS-goodness and hitting the escape button;

image

but I think it’s good to have both editors and use them when it makes sense to you.


Posted Wed, Nov 24 2010 9:43 AM by mtaulty

Comments

Austin P wrote re: Blend Bits 17–Coding in Blend
on Wed, Nov 24 2010 11:55 AM

Very confusing - as to do any true development in Silverlight you need both.  I liken this to writing iPhone apps without Interface Builder and whereas Apple is working to merge XCode and Interface Builder, Microsoft went a step backward and created Blend vs making this a part of Studio!

Blend ships with a lame code editor and VS ships with a lame SL designer interface.

Here is hope in 2011 that MS puts Blend in Studio so we can all get back to developing Silverlight apps and not stumbling over which SKU to buy our developers already fully invested in VS professional/premium licenses

Thanks for the insightful post Mike, in the end - ie your last sentence just emphasizes to me the wtf that comes to mind when I have to right click on a XAML file in VS to say 'open in blend' since my designer in VS is asking me to 'refresh' with some obtuse designer error :)

GoorySanta wrote re: Blend Bits 17–Coding in Blend
on Wed, Nov 24 2010 4:42 PM

Nice Post.  We sometimes miss the fact that Bend is a full featured environment which provides a great collections of work-flow helpers.

Barney Nicholls wrote re: Blend Bits 17–Coding in Blend
on Thu, Nov 25 2010 2:44 PM

I switch between blend and VS all the time.  Blend for the UI and VS for the code.

I always set the option in blend to do my code editing in VS

I'd really love blend to have two features/options that would make the life of a person who has to use both enviroments easier i.e

1. Reload changed documents without prompting if they've been saved e.g. i'm editing the viewmodel in vs then switch back to blend to be prompted fifteen times 'do you want to reload?' drives me nuts

2. Close all windows except this.  have you tried closing the design windows they jump around so you cant just click the x then wait for the next window, and they take forever to shut

While i'm whingeing about blend and vs how about improving the xaml editor in blend and why not in vs make the xaml view (which vs does better) the default rather than the design view which vs is not exactly great at handling

Oh well rant over

Thanks for all your work Mike and keep at it, I've found your articles more than a little helpful over the years

Barney