Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 388 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
388
Dung lượng
10 MB
Nội dung
this print for content only—size & color not accurate trim = 7" x 9.125" spine = 0.90625" 400 page count 444ppi
BOOKS FOR PROFESSIONALS BY PROFESSIONALS
®
Pro ExpressionBlend 4
Pro ExpressionBlend4 is for .NET developers, and graphical artists, who want
to learn the ins and outs of the ExpressionBlend IDE. You may know already
that this tool can be used to build Windows Presentation Foundation (WPF),
Silverlight, and Windows Phone 7 applications; however, this book will take
you well beyond the basics and provide you with a detailed examination of the
key Blend topics, including workspace customization, graphics, layout, styles,
themes, data binding, and the use of SketchFlow, giving you an excellent under-
standing of the Blend product and what it can do for you.
Over the course of these eight chapters, you will learn numerous techniques
to simplify the authoring of XAML using Blend. These include:
• Transforming a vector graphic into a custom control template with a few
clicks of the mouse
• Generating complex animations using an integrated timeline editor
• Visually designing interactive data templates
• Creating prototypes (via SketchFlow) that can be transformed into
production-level code
Throughout the book you’ll work with both Blend and .NET code to finalize
fully working projects that will provide both valuable insights and a sound
foundation for your future WPF and Silverlight projects.
Each chapter will give you ample opportunity to build .NET software using
the Blend IDE. But this is not a programming book, per se. While some examples
will require a manageable amount of C# code, this book is squarely focused to
help you gain mastery over the numerous tools, editors, designers, and wizards
of the Microsoft ExpressionBlend IDE.
Troelsen
Expression Blend 4
THE EXPERT’S VOICE
®
IN EXPRESSION BLEND
CYAN
MAGENTA
YELLOW
BLACK
PANTONE 123 C
Companion
eBook
Available
ISBN 978-1-4302-3377-0
9 781430 233770
54999
Full Color Inside
Full Color Inside
Andrew Troelsen
The essential resource for developers
Pro
Expression
Blend 4
Andrew Troelsen, Author of
Pro C# 2010 and the .NET 4
Platform, Fifth Edition
Pro VB 2010 and the .Net 4
Platform
US $49.99
Shelve in:
.NET
User level:
Intermediate
www.apress.com
SOURCE CODE ONLINE
Companion eBook
See last page for details
on $10 eBook version
RELATED TITLES
Pro
1
C H A P T E R 1
■ ■ ■
Learning the Core Blend IDE
The point of this first chapter is to examine the nuts and bolts of the Microsoft ExpressionBlend
integrated development environment (IDE). You will begin with a brief overview of each
member of the Microsoft Expression family of products, and see their place within a Windows
Presentation Foundation (WPF) and Silverlight development effort. Next, you will examine the
various project templates of Expression Blend, come to know the key workspace areas (the
artboard, the Objects and Timeline panel, the Properties panel, etc.), and understand the
interplay between ExpressionBlend and Microsoft Visual Studio 2010. The chapter concludes
with coverage of how to customize the layout of the IDE to suit your personal preferences.
The Microsoft Expression Family
The Microsoft Expression family of products was first demonstrated during the 2005
Professional Developers Conference (PDC), but it was not until 2007 that Microsoft released the
first edition of the tools to the world at large. The Expression product lineup is a set of
applications aimed at the professional graphical artist; however, it is increasingly common for
software developers to use the products as well.
At the time of this writing, the Expression family consists of four
1
products (Expression
Web, Expression Encoder, Expression Design, and Expression Blend), which may be purchased
via the acquisition of Microsoft Expression Studio Ultimate. You’ll be happy to know that if you
or your company has an MSDN subscription, Expression Studio Ultimate is part of your current
package. If you do not have a valid MSDN subscription, you will be equally happy to know that
you can download a 60-day trial edition of Expression Studio Ultimate from the following web
site:
2
www.microsoft.com/expression/try-it
Strictly speaking, this book only requires you to have access to a copy of Expression Blend.
However, if you wish to explore how to incorporate complex vector graphics into a WPF or
Silverlight application (see Chapter 2), I suggest that you install a copy of Expression Design. As
1
Or five products, if you include Expression Media, which has recently been acquired by Phase One A/S.
Expression Media is a commercial digital asset management (DAM) cataloging program for Microsoft
Windows and Mac OS X operating systems.
2
On a related note, the Microsoft Expression home page (www.microsoft.com/expression) provides
supporting links to a rich online community. You can find numerous video tutorials, case studies,
technology previews, and so forth. Take a moment to check out this site; it’s definitely worthy of a browser
bookmark.
CHAPTER 1 ■ LEARNING THE CORE BLEND IDE
2
far as the other members of the Microsoft Expression family are concerned, we will not be
making use of them in this text. Nevertheless, you may want to explore them on your own, so
the following quick tour describes the high-level nature of each member of the Microsoft
Expression family.
The Role of Expression Web
Expression Web is a tool that allows you to visually create production-ready (and standards-
based) web sites. Even though this is a Microsoft web development tool, you are not limited to
the use of ASP.NET or ASP.NET AJAX (although support for the .NET platform within
Expression Web is excellent). If you wish, you can use the integrated page designers and source
code editors to construct web sites using PHP, HTML/XHTML, XML/XSLT, CSS, JavaScript, as
well as Adobe Flash and Windows Media components.
Expression Web also ships with a companion product named SuperPreview. This aspect of
Expression Web (greatly) simplifies the testing of your web site across several popular web
browsers (for both Windows and Mac). If you are a web-savvy developer, you know that
ensuring a web page renders and behaves properly across diverse environments is a constant
source of irritation. Using Expression Web and SuperPreview, you have a solid set of tools to
help with this endeavor.
The Role of Expression Encoder
Although we will not use Expression Encoder for this book, be aware that this tool provides a
platform to import, edit, and enhance video media, encoded in a wide variety of formats
including AVI, WMV, WMA, QuickTime MOV files (if installed), MPEG, VC-1, and H.264.
By way of an example, using Expression Encoder, you could create a professional training
video configured to stream within a Silverlight (or WPF) application. As well, Expression
Encoder can be used to create media that seamlessly integrates into a WPF/Silverlight
application via bookmarks and customizable skins.
The Role of Expression Design
Expression Design is a Microsoft tool that stands in direct competition with Adobe products
such as Illustrator and Photoshop (in fact, Expression Design, as well as Expression Blend, can
import file formats from each of these designer-centric applications). In a nutshell, Expression
Design is a tool that enables graphical artists to generate rich, vector-based graphics.
As you would expect, Expression Design allows a graphical designer to save their work in a
variety of standard image formats (PNG, JPEG, GIF, TIFF, etc.). In addition, and for our
purposes more interestingly, Expression Design also allows you to save your graphical data in
WPF or Silverlight XAML.
As you may know, the Extensible Application Markup Language (XAML) is an XML-based
grammar used to describe the state of a .NET object (graphically based or otherwise). For example,
the following markup describes the look and feel for the vector image shown in Figure 1–1. Notice
that we are able to create a pleasing drop shadow effect and a complex radial gradient brush
used to fill the interior of the circle using just a few lines of XAML:
<Ellipse x:Name="shadowCircle" HorizontalAlignment="Left"
Height="117.5" Margin="99,58,0,0" Stroke="#FF0B17D6"
VerticalAlignment="Top" Width="117.5"
StrokeThickness="7">
<Ellipse.Effect>
<DropShadowEffect Color="#FFB7B8E0" BlurRadius="6"
Do wn loa d from W o w ! eB o o k < www . w o w e boo k . c o m >
CHAPTER 1 ■ LEARNING THE CORE BLEND IDE
3
ShadowDepth="11"/>
</Ellipse.Effect>
<Ellipse.Fill>
<RadialGradientBrush GradientOrigin="0.38,0.304">
<GradientStop Color="#FF111EE0" Offset="0"/>
<GradientStop Color="#FFC5C7E0" Offset="1"/>
<GradientStop Color="#FF4750DA" Offset="0.526"/>
</RadialGradientBrush>
</Ellipse.Fill>
</Ellipse>
Figure 1–1. The rendered output of the example XAML
By providing the ability to save a vector-based graphic as XAML, Expression Design makes
it very simple for a developer to incorporate professional-looking graphics into an existing
application, and interact with the data through code. For example, a graphical artist could
create a stylized 2D maze for an interactive video game. Once saved as XAML, this data can be
imported into an ExpressionBlend (or Visual Studio 2010) project and stylized further with
animations, hit-testing support, and other features. You’ll see how this is possible in Chapter 2.
The Role of ExpressionBlend
Now, as they say, on to the good stuff! ExpressionBlend is a key component for building a
production-level WPF or Silverlight application. This tool will generate a vast amount of the
XAML required by your programs. While you could author the same markup manually using
numerous development tools (ranging from Notepad to Visual Studio 2010), you will most
certainly suffer from massive hand cramps due to the verbose nature of XML-based grammars.
Well beyond the relatively simple XAML editing support provided by Visual Studio 2010,
Expression Blend supplies sophisticated tools to lay out and configure controls, author complex
animation sequences, create custom styles and templates, generate new UserControl
3
classes
from existing vector graphics, visually design data templates, assign behaviors and visual states
to user interface (UI) elements, and perform a host of other useful operations.
As you progress through the book, you will learn a great deal about using ExpressionBlend
to build extremely expressive user interfaces for the Web (via Silverlight), the desktop (via WPF),
and Windows Phone 7 (using, surprise!, Silverlight).
3
A “user control” is a .NET class (with the associated XAML) that represents a chunk of reusable UI
elements. You’ll learn how to generate user controls via ExpressionBlend in Chapter 5.
CHAPTER 1 ■ LEARNING THE CORE BLEND IDE
4
Expression Blend Is Typically Only One Side of the Coin
While ExpressionBlend does ship with a simple, lightweight C# and VB code editor (seen later
in this chapter), you most likely would not want to author all of your .NET code within this IDE
as it is fairly limited in scope (for example, no debugging support). As luck would have it, an
Expression Blend project has the exact same format as its Visual Studio counterpart. Thus, you
could begin a new project with ExpressionBlend and design a fitting UI, and then open the
same project in Visual Studio 2010 to implement complex code, interact with the debugger, and
so forth.
To be sure, a vast majority of your WPF/Silverlight applications will make use of each IDE
during the development cycle.
4
You’ll examine the integrated code editor of ExpressionBlend
and see the interplay with Visual Studio 2010 later in this chapter.
The Role of SketchFlow
In addition to providing the tools required to build rich user interfaces, ExpressionBlend also
includes a suite of tools that enables you to rapidly prototype applications using SketchFlow.
5
This aspect of ExpressionBlend allows you to quickly and effectively mock up and define the
flow of an application UI, screens layout, and application state transitions. Figure 1–2 shows a
SketchFlow project loaded within the ExpressionBlend IDE.
Figure 1–2. SketchFlow enables rapid prototyping of WPF and Silverlight applications.
4
An ExpressionBlend project is able to integrate within the Visual Studio Team Foundation source control
management system.
5
SketchFlow is only included with Expression Studio Ultimate Edition.
CHAPTER 1 ■ LEARNING THE CORE BLEND IDE
5
Because SketchFlow is intended to be used during application prototyping, you can build
UI mock-ups without being concerned with lower-level details, and can quickly adapt your
prototypes in real time based on client feedback. This is made even easier given the freely
distributable SketchFlow player, which ensures your prototypes can be demonstrated
effectively to your client. Perhaps best of all, a SketchFlow project can become the starting point
for a “real” WPF or Silverlight application. You will learn how to work with this facet of
Expression Blend in Chapter 8.
The ExpressionBlend Project Templates
Now that you understand better the overall purpose of the members of the Microsoft
Expression family, we can turn our attention to the various types of projects supported by the
Expression Blend IDE. When you launch Expression Blend, you’ll be greeted by default with the
Blend Welcome Screen. Figure 1–3 shows the contents of the Help tab.
Figure 1–3. The ExpressionBlend Welcome Screen
As you can see, this Welcome Screen is divided into three tabs, Projects, Help, and Samples.
For the time being, select the Projects tab, and click the New Project option. Once you do, you’ll
be presented with the New Project dialog box, shown in Figure 1–4.
6
6
Notice in Figure 1–4 that the mouse cursor is located over a vertical UI element that allows you to show or
hide the leftmost project template tree view.
CHAPTER 1 ■ LEARNING THE CORE BLEND IDE
6
Figure 1–4. The ExpressionBlend New Project dialog box
Regardless of which project template you select, you will find that the New Project dialog
box allows you to specify a name and location for your new project, as well as select between a
C# or VB code base. Last but not least, you are able to configure your new project to target a
specific version of the .NET (for WPF projects) or Silverlight platform.
■ Note In this book, I will assume you are making use of C# as you work through the various examples. If you
would rather use VB, you should not have any difficulties mapping the minimal C# code into the syntax of VB.
WPF Project Templates
If you are interested in creating a new, rich desktop application for the Microsoft Windows
operating system, chances are you’ll be starting with a new WPF application. As of Blend 4, the
WPF node of the New Project dialog box provides four starter templates, each of which is
documented in Table 1–1.
CHAPTER 1 ■ LEARNING THE CORE BLEND IDE
7
Table 1–1. WPF Project Templates of ExpressionBlend
WPF Project Template Meaning in Life
This template is for building a traditional desktop WPF executable.
This template is for creating reusable .NET class libraries that
contains custom WPF controls. You will learn about building
custom user controls (and styles/templates) in Chapter 5.
This template is also for building a traditional desktop application,
but it uses View and ViewModel objects (and the MVVM design
pattern) to provide loose coupling between your presentation and
data logic
7
.
This template allows you to prototype a new WPF desktop
application using SketchFlow (see Chapter 8).
Silverlight Project Templates
Table 1–2 documents the web-centric Silverlight project templates of Expression Blend, which
can be viewed by clicking the Silverlight node of the New Project dialog box. As you can see,
they are similar to their WPF counterparts.
Table 1–2. Silverlight Project Templates of ExpressionBlend
Silverlight Project Template Meaning in Life
This template is for creating a new Silverlight application and a
corresponding web site project that hosts it.
This template is for creating a new Silverlight application. You
w
ill not get a full web site project with this option, but Blend
w
ill autogenerate a simple HTML test page (Default.html)
w
hen you run your project.
This template is also for creating a Silverlight application, but it
uses View and ViewModel objects (and the MVVM design
pattern) to provide loose coupling between your presentation
and data logic.
This template is for creating reusable .NET class libraries that
contain custom Silverlight controls. You will learn about
building custom user controls (and styles/templates) in
Chapter 5.
This template allows you to prototype a new Silverlight
application using SketchFlow (see Chapter 8).
7
Chapter 6 will briefly examine this project type; however, detailed coverage of the MVVM design pattern is
beyond the scope of this book.
CHAPTER 1 ■ LEARNING THE CORE BLEND IDE
8
Now, the good news is that a majority of the Blend IDE will remain the same, regardless of
which of the project templates you select. Of course, always remember that WPF and Silverlight
are not perfect carbon copies of each other. While they are both forged from the same
technologies (XAML, a control content model, etc.), their codebases are not 100 percent
compatible.
By way of one simple example, the WPF API provides support for full 3D vector graphics,
whereas Silverlight ships with only simple (but still very useful) 3D perspective graphics. As
well, WPF supports a deeper (or as some would say, more complex) model to handle UI cues via
markup using triggers or the Visual State Manager (VSM), whereas Silverlight opts to deal with
UI cues in XAML using the VSM (almost) exclusively.
Windows Phone Project Templates
At the time of this writing, Microsoft is preparing to launch the Windows Phone 7 family of
mobile devices.
8
As you might already know, the native development platform of Windows
Phone 7 is in fact Silverlight! Given this point, be aware that the Blend IDE (as well as Visual
Studio 2010) can be updated to support a variety of Windows Phone 7 project templates via a
free web download.
I’m sure that the next release of ExpressionBlend will ship with these templates
preinstalled. In any case, Chapter 7 will introduce you to the topic of using Blend to build UIs
for Windows Phone 7 devices, and at that time, I’ll show you how to download and install the
required SDK and project templates if they are not already on your development machine.
■ Note You will be happy to know that almost everything you will learn about using Blend to build a WPF or
Silverlight project applies directly to a Windows Phone 7 project.
A Guided Tour of the Core Blend IDE
You will begin to build your own ExpressionBlend projects beginning in Chapter 2. For the time
being, I will give you a tour of the key aspects of the IDE by loading one of the supplied sample
projects. I feel this will be helpful in that you will be able to see a “real” project as you learn the
lay of the land, and you will also have a much better idea of what sorts of applications you can
create with WPF and Silverlight.
Assuming the New Project dialog box is still open on your screen, press the Esc key on your
keyboard to return to the Blend Welcome Screen (if you already dismissed the New Project
dialog box, you can open the Welcome Screen once again using the Help
➤ Welcome Screen
menu option). In any case, click the Samples tab, shown in Figure 1–5, and notice you have a set
of built-in sample projects.
8
Consult www.microsoft.com/windowsphone for more information regarding Windows Phone 7.
CHAPTER 1 ■ LEARNING THE CORE BLEND IDE
9
Figure 1–5. The Welcome Screen allows you to open a number of sample projects.
The exact list of sample projects you will see varies between different versions of
Expression Blend, so don’t be too alarmed if your list does not match Figure 1–5 to a tee. For
this portion of the chapter, I will be using the Silverlight ColorSwatchSL sample project;
however, you are free to load any project you wish to explore.
Loading a Blend Sample Project
Before we dive into the IDE, let me tell you how to run a Blend project so you can test how the
application is coming along. When you press the F5 key, or the Ctrl+F5 keyboard combination,
Blend will build and run your current project. If you are building a WPF application, the end
result will typically be that a new window appears on your desktop. On the other hand, if you
are building a new Silverlight application, you will find that your web browser will load up and
display the hosting web page.
Go ahead and run the ColorSwatchSL project now. Notice that as you move your mouse
over any of the colored strips, they pop forward via a custom animation. If you click any colored
strip, a “details” area springs into view using another animation sequence. Figure 1–6 shows a
possible test run.
[...]... and IntelliSense and provides useful help information Figure 1–12 The ExpressionBlend XAML editor is quite feature rich That wraps up our look at the ExpressionBlend artboard Next up, let’s examine ways to view and configure the UI elements that populate the designer area 14 CHAPTER 1 ■ LEARNING THE CORE BLEND IDE The Objects and Timeline Panel The next important aspect of the Blend IDE to consider... Visual Studio, ExpressionBlend uses a solution/project metaphor A single solution can contain multiple projects, which collectively represent the application you are constructing Consider Figure 1–18, which shows items for both projects and also illustrates the process of adding new items to a given project via a standard right-click mouse operation (we are not really adding anything to either project right... very common property categories, listed alphabetically Table 1–3 Common Categories of the Properties Panel Blend Property Category Appearance This category controls general rendering settings, such as opacity, visibility, and the application of graphical effects (blurs, drop shadows, etc.) Brushes This category provides access to the visual brush editor Common Properties This category contains properties... of the Blend IDE (as they say, the journey of a thousand miles begins with a single step) First, you learned the role of each member of the Expression line of produces (Web, Encoder, Design, and Blend) After that, we quickly moved into an initial exploration of the Blend IDE through the use of a canned sample project The artboard panel is the primary designer area for any new WPF or Silverlight project... topics, such as the Brushes editor), launch ExpressionBlend and create a new WPF application or Silverlight application project named BlendDrawingTools It really does not matter which type of project you create, as these basic drawing tools work identically for WPF and Silverlight projects For this example, I will opt for a WPF application (see Figure 2–1) 34 CHAPTER 2 ■ VECTOR GRAPHICS AND OBJECT RESOURCES... artboard control area is used to view or hide Blend annotations You can think of annotations as a Blend programmer’s version of a sticky note Using annotations, you 12 CHAPTER 1 ■ LEARNING THE CORE BLEND IDE can add textual notes to your current design, which can be particularly useful during the prototyping phase (see Chapter 8) Currently, the ColorSwatchSL sample project does not have any annotations; go... 13 CHAPTER 1 ■ LEARNING THE CORE BLEND IDE Viewing and Editing the Underlying XAML If your primary role at your company is that of a graphical artist, you may not be terribly interested in viewing the XAML that ExpressionBlend is creating on your behalf However, if you are a software developer who is making use of Blend, you’ll be happy to know that the Blend IDE does provide a sophisticated XAML editor... insertion operation) Figure 1–18 The Project panel shows you a project-by-project and file-by-file breakdown of your current solution The Integrated Code Editor While XAML allows you to do some amazing things without ever writing a single line of C# or VB code, your projects will eventually need some code to drive their functionality Earlier editions of the ExpressionBlend IDE did not ship with any sort... (*.cs) or VB (*.vb) code file within the Projects panel, Blend would automatically launch Visual Studio (or Notepad if Visual Studio was not installed) Nowadays, Expression Blend does indeed have a useful code editor To view this for yourself, double-click the ListBoxItemSendToTop.cs code file (or any code file of your choosing) found within the Project panel The Blend code editor is useful when you wish...CHAPTER 1 ■ LEARNING THE CORE BLEND IDE Figure 1–6 The running ColorSwatchSL application Once you have finished testing the sample program, close your browser and return to Expression Blend The Artboard and Artboard Controls The “artboard,” located in the center of the IDE, is perhaps the most immediately useful aspect of Expression Blend, in that you will use this visual designer . spine = 0.90625" 40 0 page count 44 4ppi
BOOKS FOR PROFESSIONALS BY PROFESSIONALS
®
Pro Expression Blend 4
Pro Expression Blend 4 is for .NET developers,. designers, and wizards
of the Microsoft Expression Blend IDE.
Troelsen
Expression Blend 4
THE EXPERT’S VOICE
®
IN EXPRESSION BLEND
CYAN
MAGENTA
YELLOW
BLACK