Code editing and Visual Studio 2005 interoperability
- What project tasks can you perform in Expression Blend?
- What can you create in Expression Blend without using code?
- What can you only do in code?
- What can you only do in Visual Studio 2005?
- How does Expression Blend help you add code?
- Where can I get help writing code?
Editing code can be a daunting task to someone who does design work. Microsoft® Expression Blend™ was designed with creative people in mind. You can create entire Windows®-based applications in the Design view of Expression Blend, as well as style resources that you can reuse in other Expression Blend projects. Additionally, you can import art assets that have been exported from Microsoft® Expression Design and use them in your Expression Blend projects.
Expression Blend was also designed with team development in mind. Often, software teams are made up of designers who work on the user interface (UI) and programmers who work on the code that runs behind the UI. For this reason, Expression Blend includes features for generating minimal code that can be handed off to developers, and features that allow you to hook into existing code such as event handlers or custom controls that can be used like existing controls.
What project tasks can you perform in Expression Blend?
- Create a project for a Windows-based application (.exe) or a user control (.dll), both of which can leverage the features of the Windows Presentation Foundation (WPF) by default.
- Add a new Extensible Application Markup Language (XAML) file (and corresponding code-behind file) to create a top-level window in your application, a user control, a navigable page within your application, or a resource dictionary that can contain reusable styles, control templates, brush resources, and so on.
- Add existing files to your project or link to existing files, such as image, XML, video, audio, license, XAML, or code files.
- Add references to existing custom controls that are
contained in .dll files. Custom controls can also be contained in existing source code files (.vb
or .cs). After you add a custom control to your Expression Blend project, you can use
it in the same
way that you use the controls that come with Expression Blend.
For an example of a custom control that is contained in a .cs file, see Create a custom control.When you add source code files that contain custom controls to an Expression Blend project, you must build the project before you can see the controls in the User Controls tab of the Asset Library in the Toolbox. - Open any file that is in your project. XAML files open on the artboard for editing, image files open on the artboard, and sound and video files open in the animation timeline. Other files will open in an external editor that is mapped to the file type. For example, if you double-click an .xml file under Files in the Project panel of Expression Blend, the file will most likely open in Notepad. Code files will open in Microsoft® Visual Studio® 2005, if it is installed. For more information, see Edit a code-behind file.
- Open a Visual Studio 2005 project or solution for a Windows-based application and create the
UI.
The elements in the Toolbox in Expression Blend require project references to Windows Presentation Foundation (WPF) assemblies. If you open a Visual Studio 2005 project in Expression Blend, make sure that the following files are listed in the Reference folder in the Project panel. You can add these files from C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0. - PresentationCore.dll
- PresentationFramework.dll
- WindowsBase.dll
- Debug your application by building (CTRL+SHIFT+B) or running (F5) it, and resolve any error messages that you might receive, in the Results panel.
What can you create in Expression Blend without using code?
- Design the look (UI) of your application by adding and transforming elements from the Toolbox, and styling them by using brushes and other properties in the Properties panel. For more information, see Controls, Drawing, Layout, and Appearance.
- Animate elements in your application. For more information, see Animation & interactivity.
- Manipulate the timelines of video or audio files in your project, after you add them to the artboard by double-clicking them in the Project panel. For more information, see Media in this User Guide.
- Trigger animation timelines, audio files, and video files from user actions, such as clicking a button or moving the mouse pointer over an element. For more information, see Animation & interactivity.
- Create and design a custom user control. A user control is a project type that you can create in Expression Blend. User controls can be used the same way as custom controls that are developed in Visual Studio 2005. For an example, see Create a user control.
- Customize the look of an existing control and then apply the resulting style template to other controls of the same type. You can also add animation to a control template. For examples, see the Try it! topics that are listed in Simple styles.
- Create other reusable resources, such as brush resources, by clicking the name of a property in the Properties panel and the clicking Convert to New Resource. For an example, see Create a brush or color resource.
- Convert elements to buttons and brush resources, or convert images to 3D objects, by using the options on the Tools menu. For examples, see Make an object into a button, and Convert a 2D image into 3D.
- Bind a property of an element to the value that is contained in another property. This is useful in many ways such as making the width of an element correspond to a slider bar. For an example, see Create and apply a value converter.
- Bind a property of an element to a data source, such as an XML file or a
common language runtime
(CLR) object.
For an example of how to use an XML data source, see Creating an RSS news reader.
What can you only do in code?
- Define more complicated behavior in event handlers when a user interacts with the UI elements of your application. Event handlers can be programmed to respond to key-presses, mouse actions, and so on. For a list of events, see Events quick reference in this User Guide. This is different than event triggers for animations, media, and video. For example, event handlers allow you to use mathematical equations to program the behavior of your application. For an example, see Create a new event handler method.
- Customize the behavior of existing controls, or create new custom controls. For an example of a custom control that is based on the WPF Button control, see Create a custom control.
- Load data, such as Microsoft® SQL Server™ data, into a data table and convert it to a CLR data object that can be used in Expression Blend. For an example, see Create a CLR object data source.
- Create a value converter to add custom logic to a data binding. This is useful if you want to bind a property of one element to a property of an incompatible data type. For an example, see Create and apply a value converter.
What can you only do in Visual Studio 2005?
- Debug your application by stepping through it line by line, while the application is running. For more information, see Debugging Expression Blend applications in this User Guide.
- Add new code files to a project.
- Edit code files. If you double-click a code file in the
Projects panel of Expression Blend, the file will open in Visual Studio 2005 if
it is installed.
For more information, see
Edit a code-behind file.
If you want to edit a code file, it is more useful to open your project in Visual Studio 2005 than to open just the code file. When you open a project in Visual Studio 2005, you can use the IntelliSense feature that offers to complete some words as you type them. For example, create a new project in Expression Blend, save it, and then open the project in Visual Studio 2005. Open the Window1.xaml.cs file, place your cursor at the beginning of the blank line after this.InitializeComponent();
, and then typeLayoutRoot
. A dropdown list displays to show you all the things that you could type on this line. If you add a period afterLayoutRoot
, the list changes to display all of the available properties and methods of the LayoutRoot element in your Window1.xaml file. - Add a new project to a solution. Expression Blend can open Visual Studio 2005 solution files.
- Add a reference to a project file or a COM API . Expression Blend will honor a reference to a project file (such as a .csproj file) and treat it the same as a reference to a .dll or .exe file.
- Create XAML browser applications (XBAPs) that will run on the Web.
To create new XAML applications and XAML Browser applications (XBAPs) in Visual Studio 2005, you need to install the extensions for .NET Framework 3.0. These can be downloaded from MSDN. (You do not need the extensions to debug XAML applications that were created with Expression Blend.) |
How does Expression Blend help you add code?
- Expression Blend optionally creates a corresponding code-behind file for any XAML file that you create by using the Add New Item wizard. If you double-click a code file in the Projects panel of Expression Blend, the file will open in Visual Studio 2005 if it is installed. For more information, see Edit a code-behind file.
- Expression Blend generates code for an empty event handler method when you double-click an event in the Properties panel (click the Events button to see a list of events). Expression Blend copies the initial code for the method to the Clipboard. If you have Visual Studio 2005 installed, Expression Blend will automatically open your project in Visual Studio 2005 and paste the method into your code-behind file. Otherwise, you can manually open the file and paste in the code. You can then add programming logic inside the event handler method, or send the code file to whoever will add the programming logic. For more information, see Event Handling in this User Guide.
You can have the same project file open in Expression Blend and in Visual Studio 2005 at the same time, on the same computer. When you save a change to a file in one system, you will get a notification when you switch to the other system, asking if you want to reload the file. |
If more than one person needs to work on the same project at the same time, we recommend that you use a source control system such as Microsoft® Visual SourceSafe®. A source control system maintains a central repository for project files that you can check out and edit locally on your computer. You can prevent other people from checking out files while you edit them, or you can configure some source control systems to merge changes that are made by more than one person to the same file. Visual SourceSafe is integrated with Visual Studio so that you can check out a file by opening it in Visual Studio. For more information, see the Visual SourceSafe section of MSDN. |
Where can I get help writing code?
If you need help writing code for your Expression Blend application, you can use one of the resources listed at Windows Presentation Foundation resources. These include a link to the newsgroup discussion.