Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
com
n
WPF-Based Code Editor
n
“Generate From Usage” Tool
n
Multi-Targeting Designer
n
Common Shortcuts, tips and more...
By Alessandro Del Sole
Creating applications
INTRODUCTION
You create .NET applications in Visual Studio 2010 by first
creating projects. A project is the place where all the parts
The new version of the Visual Studio 2010 Integrated
composing your application, such as code, libraries, dialogs,
Development Environment ships with a number of new
pages and resources, reside. An application can be composed
important features. Such features are both related to the IDE
of one or more projects. Multiple projects bound together
architecture and to the coding experience, with the addition of
are combined into a Solution. Thus, the first step is creating a
new tools as well. This Refcard is a quick reference to the most
new project. You accomplish this by selecting the New|Project
important new features and instruments in Visual Studio 2010,
command from the File menu. This will show the New Project
also providing tips to most common shortcuts.
dialog which looks like this:
STARTING WITH VISUAL STUDIO 2010
Visual Studio 2010 is the developer tool used for creating .NET
www.dzone.com
Visual Studio 2010 offers a convenient way for managing the
most recently used projects by simply right-clicking each
project name in the list. With this action you can pin or remove
items from the list itself.
In Visual Studio 2010 you can also target different versions of • Improved extensibility: the code editor also takes
the .NET Framework (as shown in the figure above) or search advantage of MEF (Managed Extensibility Framework) to
specific project templates using the Search Installed Templates receive pluggable components. This allows hosting rich
search box. content inside the code editor, such as images, videos,
WPF controls, comment adornments and so on.
Building and debugging applications
• Reusability: you can reuse the code editor as a
You can build and run your executable application by pressing
component in your own Visual Studio add-ins.
F5. This is common to both Windows and Web applications
and will run your application with an instance of the Visual You interact with the code editor via the IWPFTextView
Studio debugger attached. Visual Studio provides a lot of interface which is described in the MSDN Library. The following
debugging tools available in the Debug menu. For example, image shows how the WPF-based code editor looks:
you can place breakpoints (also by pressing F9) or check for the
value of local variables via the Locals tool window. If you don’t
want to run the application under the debugger investigation,
simply press Shift+F5.
Click Generate ‘Class Contact’ and Solution Explorer you will Here you can:
notice the presence of a file named Contact.vb (or .cs in C#) • Provide the new object’s visibility by setting the
which contains the empty definition of the new class. Access property
• Decide what kind of object you want to create from the
The class declaration gets the default visibility Kind property
modifier, according to the current programming • Add the new member to a different project in your
Hot language, which is Friend for Visual Basic and
Tip solution via the Project combo box
Internal for C#. You need to change this manually if • Create a new code file or add the new object to an
you want to expose the class outside the assembly. existing code file inside the File Name box
Now you can populate your class with new members, like in Simply click OK when you are done and the new object will
the following figure, where the code attempts to assign a be added to your solution according to the specified settings.
non-inexistent property, but the IDE provides the possibility of At this point you can add new members as described in the
generating a property or a field: previous section.
The Data Sources window in Visual Studio 2010
Hot provides full support for entities exposed by the
Tip Entity Framework.
As in older technologies, you can still create grid views or Dim CategoriesQuery As System.Data.Objects.ObjectQuery(Of
details views and you are allowed to replace the default WpfApplication1.Category) =
NorthwindEntities.Categories
controls with different ones. You can drag an entire object to ‘Update the query to include Products data in Categories. You
can modify this code as needed.
create a view or a single object onto an items container control CategoriesQuery = CategoriesQuery.Include(“Products”)
such as the ListBox for creating lists. ‘Returns an ObjectQuery.
Return CategoriesQuery
End Function
Visual Studio adds controls to the user interface
Private Sub Window_Loaded(ByVal sender As System.Object,
depending on the version of the .NET Framework you
Hot are targeting. For example, if you want to create a RoutedEventArgs) _
ByVal e As System.Windows.
Next it generates data-bound controls, such as a DataGrid WPF & SILVERLIGHT: MULTI-TARGETING DESIGNER
and Label/TextBox couples if considering the previous
image (notice the Binding markup extension pointing to the In previous versions of Visual Studio the design-time
bound property): experience for WPF and Silverlight developers did not offer
specialized design tools. For WPF developers, the IDE lacked
<DataGrid AutoGenerateColumns=”False” EnableRowVirtualization=”True”
Height=”128” HorizontalAlignment=”Left” ItemsSource=”{Binding}” some tooling familiar to Windows Forms developers. Visual
Name=”CategoriesDataGrid” RowDetailsVisibilityMode=”VisibleWhenSelect
ed” VerticalAlignment=”Top” Width=”248”> Studio 2008 introduced some improvements to the WPF
<DataGrid.Columns> design experience, like the ability to drag controls from the
<DataGridTextColumn x:Name=”CategoryIDColumn”
Binding=”{Binding Path=CategoryID}” Header=”Category ID” toolbox and drop them onto the designer surface, or the
Width=”SizeToHeader” />
<DataGridTextColumn x:Name=”CategoryNameColumn”
possibility to access event handlers by double-clicking the
Binding=”{Binding Path=CategoryName}” Header=”Category Name” controls. But no support was available for setting special
Width=”SizeToHeader” />
<DataGridTextColumn x:Name=”DescriptionColumn” properties inside the Properties Window (e.g. brushes) so
Binding=”{Binding Path=Description}” Header=”Description”
Width=”SizeToHeader” />
developers needed to manually write the code to set them. For
</DataGrid.Columns> Silverlight developers, things were even worse, in that you had
</DataGrid>
… neither drag and drop support nor design time support such
<Label Content=”Product ID:” Grid.Column=”0” Grid.Row=”0” as adjusting the application layout, so everything had to be set
HorizontalAlignment=”Left” Margin=”3” VerticalAlignment=”Center” />
<TextBox Grid.Column=”1” Grid.Row=”0” Height=”23” in code. Although Visual Studio is a developer tool, Microsoft
HorizontalAlignment=”Left” Margin=”3” Name=”ProductIDTextBox”
Text=”{Binding Path=ProductID, Mode=TwoWay, Expression Blend is the tool best suited for deep customization
ValidatesOnExceptions=true, NotifyOnValidationError=true}” of the user interface. While lots of developers use only Visual
VerticalAlignment=”Center” Width=”100” />
… Studio to create the user interface for their applications, the
need for better VS designer program was paramount. This is
It is worth mentioning that Visual Studio also maps data
what happened with the release of Visual Studio 2010. In the
types to the appropriate controls. A typical example is when
next section you get an overview of the new and improved
you have data of type System.DateTime that is represented
features, while later you will get information about how this
via a DatePicker control (available in .NET 4 only). On the
targets multiple .NET Framework versions.
managed code side, Visual Studio generates some starting
code for querying data. In case you use the Entity Framework Improved experience
as the Data Access Layer, the generated code looks like this With Visual Studio 2010, both the WPF and Silverlight
(continuing the example from the previous image): designers now provide a full design-time experience and,
most importantly, both technologies share the same tools. This
Class MainWindow
means that you have the same instrumentation available for
Private Function GetCategoriesQuery(ByVal NorthwindEntities As _
WpfApplication1.
both WPF and Silverlight projects. You now have full support
NorthwindEntities) _ for dragging and dropping controls from the toolbox, for
As System.Data.Objects.
ObjectQuery(Of WpfApplication1.Category) rearranging controls on the controls’ surface and you can also
set complex properties within the Properties Window. The
following figure represents such a description with regard to a This way you can easily reach and set the properties you want
WPF project: to assign.
#82
CONTENTS INCLUDE:
■
■
About Cloud Computing
Usage Scenarios Getting Started with
Aldon Cloud#64Computing
■
Underlying Concepts
Cost
by...
■
Upcoming Refcardz
youTechnologies ®
■
Data
t toTier
brough Comply.
borate.
Platform Management and more...
■
Chan
ge. Colla By Daniel Rubio
tion:
dz. com
tegra ternvasll
ABOUT CLOUD COMPUTING one time events. TEN TS
INC ■
HTML LUD E:
us Ind Anti-PPaat
Basics
Automated growthHTM
ref car
nuorn
■
Valid
ation one time events, cloud ML
connected to what is now deemed the ‘cloud’. Having the capability to support
Network Security
Usef
Du
ti
■
ul M.
computing platforms alsoulfacilitate
Open the gradual growth curves
n an
Page Source
o
■
s
Vis it
C
faced by web applications. Tools
Core
By Key ■
Elem
atte
E: has changed substantially in recent years, especially with ents Structur
LUD al Elem
TS INC gration
P the entrance of service providers like Amazon, Google and Large scale growth scenarios involvingents
specialized
and mor equipment
rdz !
HTML
ry Microsoft. e chang
es e... away by
(e.g. load balancers and clusters) are all but abstracted
Con at Eve
About ns to isolat
relying on a cloud computing platform’s technology.
Software i-patter
space
ALM
n
Re fca
e Work
Build
riptio
and Ant
Desc
These companies have a Privat
are in long deployedtrol repos
itory
webmana applications
ge HTM
L BAS
Patterns Control lop softw n-con to
■
that adapt and scale
Deve
les toto large user
a versio ing and making them
bases, In addition, several cloud computing ICSplatforms support data
ize merg
ment
rn
Version e... Patte it all fi minim le HTM
Manage s and mor e Work knowledgeable in amany
ine to
mainl aspects related tos multip
cloud computing. tier technologies that Lexceed the precedent set by Relational
space Comm and XHT
■
Build
re
Buil Repo
This Refcard active
will introduce are to you to clouddcomputing,within units with an
RATION etc. Some platforms ram support large grapRDBMS deployments.
■
The src
dy Ha
softw
and Java s written in on of
riente
e ine loping hical
INTEG
task-o it attribute
softwar
Mainl emphasis onDeve es by all
S these
ines providers, so youComm can better understand
also rece JavaScri user interfac web develop and the rris
Solr
chang
codel desc
INUOU Task Level
ding e code as the
www.dzone.com
Subversion
reposit s that Pay only cieswhat you consume
tagge or Amazon’s cloud you cho platform
computing
the curr isome
heavily basedmoron fine. b></ ed insid
lained ) and anti the part solution duce nden For each (e.g. WAR es t
ent stan ose to writ more e impo a></ e
not lega each othe
exp x” al Depe ge nmen b> is
be text to “fi ns are Web application deployment until
nden a few years
t librari ago was similar
t enviro industry standard
that will softwaredard and virtualization app
e HTM technology. rtant,
to pro Minim packa
Mo re
ML shar
tern. term
Privat
(starting from zero) by Perfo all majorated cloud
feedb computing platforms. on As a user of Amazon’s
n HT EC2 essecloud
nti l computing es c platform, you are result elopers rs add
ed layo anyb
he pat tion f he le this h s d d utom they occur ld based i c d