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;
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;
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;
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;
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;
then hitting CTRL+SPACE will bring up the IntelliSense;
and continuing to select a function and attempt to call it will do a similar thing when I hit the opening brace;
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;
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;
What you’re confronted with is the standard Windows file dialog;
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;
Here’s an example of the folders you might set up;
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;
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;
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;
but I think it’s good to have both editors and use them when it makes sense to you.