CreateObject "WScript. Using the WShell SendKeys method we can send input to the currently focused application. This feature is extremely useful for integration testing. Using The Shell. Application class we can iterate over all applications, check their Verbs and execute those verbs accordingly.
Here are the Verbs for the Calculator application:. However, this method allows us to Pin Calculator to the Win7 taskbar even when the Calculator is closed. CreateObject "Shell.
NameSpace 23 ;. ParseName "Calculator. Item i ;.
Beginning Silverlight 4 in C# (Expert's Voice in Silverlight)
DoIt ;. Essentially, what this method does is: 1. Gets the path for all the users start menu links. Gets the specific link for Calculator. Checks what Verbs are available for that link. Using the Shell. NameSpace 11 ;. ParseName Deployment. OOBLink ;. Show "Please restart your machine and this application will load on startup. First, we get the LNK to the current out-of-browser application by checking the start menu links directory.
Next, we add that LNK file Uri to the registry node we mentioned earlier on. Show "Close this application and start it up again from Win7 Taskbar" ;. SpVoice class for Text2Speech. My HoverCraft is full of eels. Clicking the button does indeed cause Windows to start speaking. SpInprocRecognizer class. For one thing, Commands should use parameters and not strings.
It is important to discuss best practices at this point. It is not my intent to advocate executing local SQL statements in conjunction with a local database. In that case, it would be much more acceptable to use ODBC. However, due to the lack of tools allowing Microsoft. NET developers to integrate Flash into their applications, to those developers Flash just seemed like a tool for adding some pretty effects to a web page, but nothing functional.
Then a wonderful thing happened when Adobe purchased Macromedia. All of the sudden, Flash was married to some of the development tools offered by Adobe. Silverlight is the technology that many. NET developers have been waiting for. What exactly is Silverlight? And, what impact does Silverlight actually have on us as. NET developers? What Is Silverlight? As I explained in the previous section, all RIAs have one characteristic in common: a client runtime that sits between the user and the server.
Specifically, Silverlight is a cross-platform, cross-browser plug-in that renders user interfaces and graphical assets on a canvas that can be inserted into an HTML page. Using XAML, you can also specify timelines, transformations, animations, and events. You can see that this XAML simply defines a rectangle on a canvas, as well as the properties associated with that rectangle, including its name, location, size, color, and border.
This simple example is just intended to give you an idea of what XAML looks like. NET Framework. NET was released a number of years ago, one of the benefits touted was cross- browser support. Developers would need to have only one code base, and that code base would work in all modern browsers. For the most part, this is true.
No matter which browser you are using, the application will function. However, in order to receive all of the bells and whistles offered by the ASP. NET controls, you must use the latest version of Internet Explorer. If you are using any other browser, you actually get a downgraded version of the web site, which contains fewer features. Validation controls are a prime example. If you are using a browser that ASP. If you are using any other browser, the validation controls still function, but require a postback to the server to do the validation.
So, although ASP. NET is cross-browser, users can get different experiences, depending on which browser they are using. With Silverlight, this changes. Microsoft is once again pulling out the term cross-browser, and also adding cross-platform, and this time they mean it. As a developer, you can create a Silverlight application and rest assured that it will run exactly the same on all supported platforms and browsers. Currently, two platforms are supported. Naturally, the first is Windows-based platforms, and the second is Mac OS platforms. This leaves one large platform unsupported: Linux.
Although Microsoft does not have plans to support Linux, others do. Moonlight is an open source implementation of Silverlight, targeted primarily at Linux based operating systems. Moonlight is part of the Mono project, an open source initiative to develop and run. Although Moonlight brings Silverlight features to Linux, the project lags behind the aggressive Microsoft release cycles. The latest version of Moonlight is version 3 Preview 6, which comes close to compatibility with Silverlight 3.
Cross-Platform Version of the. NET Framework Silverlight 1. Although Silverlight 1. Silverlight 1. Silverlight 2 and beyond contains its own cross-platform version of the. NET Framework programming library that you can use in Visual Studio to build rich user experiences in the browser. The Visual Studio integrated development environment IDE has been around for quite some time, and although new features are continually added to the tool, the environment itself has remained remarkably consistent.
Silverlight development is no different. This gives Silverlight a distinct advantage, as developers do not need to learn how to use a new development environment. While Expression Blend looks completely different, it still has many of the same elements as Visual Studio. In addition, Expression Blend works off of the same project as Visual Studio. This means that as you make changes in each of the editors—opening a project in Visual Studio, and then opening the same project in Expression Blend to edit the XAML—the edited files will request to be refreshed when opened again in the other tool.
Small Runtime and Simple Deployment Since Silverlight requires that a client runtime be installed on the client machine, it is vital that this runtime has a small footprint and downloads quickly. Microsoft worked very hard to get the installation size as small as possible. The developers clearly succeeded with Silverlight 1.
For Silverlight 2, however, they had a harder chore ahead of them, since Silverlight 2 contains its own. NET Framework and object library. Microsoft went to each. NET Framework team and allocated it a size to fit its portion. The end result is astonishing—Silverlight 2 is approximately 4MB in size. In Silverlight 4, even with the large amount of new features that have been added to the Silverlight runtime, the file size is still less than 6MB.
As for pushing the Silverlight runtime out to clients, Microsoft has provided a very easy detection mechanism. If the client does not have the proper Silverlight runtime installed, it will display a logo, similar to the one shown in Figure Once the runtime is finished installing, the Silverlight application is immediately available to the user. However, with Silverlight, the situation is quite a bit different due to the introduction of many new tools. For your Silverlight environment you should install Visual Studio , which automatically installs Microsoft. NET Framework 4.
Chapter 2 covers Visual Studio in more depth. Microsoft Visual Studio 2. Expression Blend 4: The next thing to install for your Silverlight development environment is Expression Blend see Figure Expression Blend is not required for creating Silverlight solutions, but provides a richer designer than does Visual Studio Expression Blend 4 is covered in detail in Chapter Silverlight 4 Toolkit. The Silverlight Toolkit is an open source CodePlex project whose goal is to develop additional controls for Silverlight applications.
Controls within the toolkit are assigned a status that describes their maturity as controls and the controls are supported by the open source community. The Toolkit is discussed in Chapter 6. New Features in Silverlight 4 Silverlight continues to evolve and Microsoft continues to add new features to Silverlight in each version. There are many new features introduced in Silverlight 4. This section will go over some of those new features and will indicate where those features are discussed in this book.
Elevated Trust Silverlight Applications are discussed in Chapter This is no different with Silverlight 4, which has added a number of new controls such as the RichTextArea and ViewBox control.
These controls are discussed in Chapters 3 to 6. In addition to web cams and microphones, additional support for mouse wheel and right mouse click has also been added to Silverlight 4. Device Support is discussed in Chapter Silverlight 4 includes an extensible printing API that will allow developers to enable client printing from a Silverlight application.
Developers can either print the contents of a visual tree from within the Silverlight application, or they can construct a custom visual tree that will allow end users to print customized views of data directly from Silverlight. Silverlight 4 adds official support for Google Chrome, which means that Silverlight 4 is supported in virtually all mainstream browsers.
This is something that has not been possible in previous versions of Silverlight. Silverlight 4 adds the ability to drag files onto out of browser Silverlight applications. This is another feature that comes nearly directly from WPF. Currently only files are supported, but it is clear in the implementation that additional drag types are on the way in future releases of Silverlight.
Read more about enabling your Silverlight applications as drop targets in Chapter The standard that has formed in the industry is notification pop-ups also referred to as toast. These are small message windows that appear in the bottom right of the screen in Windows and in the top right hand part of the screen on Mac OS. Silverlight 4 adds support for toast messages that allow developers to add notification to Silverlight applications.
If you do, the application will automatically escape out of full screen mode. Silverlight 4 fixes this problem, by adding support for keyboard access in full screen mode. Improved Performance With each new release of Silverlight, besides adding a number of new features, Microsoft has thrived to continue to improve the performance of the Silverlight runtime. Silverlight 4 continues this trend and offers significant performance improvements over pervious Silverlight versions. Summary In this chapter, you looked at the evolution of user interfaces in applications, as well as the history of RIAs.
I then introduced Silverlight, talked about the benefits it brings to developers today, and how it fits into RIA solutions. Finally, you learned about the tools involved in developing Silverlight-enabled applications. Now it is time to get your hands dirty and start building some Silverlight applications! In the next chapter, I will provide an introduction to Microsoft Visual Studio , one of the primary tools used to build Silverlight applications. This chapter provides an introduction to Visual Studio , the latest version.
You will learn about some of the new features that are particularly helpful for developers building RIAs with Silverlight, and you will have an opportunity to create your first Silverlight application using Visual Studio What Is Visual Studio? NET has used some version of Visual Studio on a regular basis. Whether you are developing desktop applications, web applications, mobile applications, web services, or just about any other. NET solution, Visual Studio is the environment you will be using. Visual Studio is an IDE that allows.
NET developers to implement a variety of. NET solutions within the confines of one editor. An IDE is a software application that contains comprehensive facilities to aid developers in building applications. Visual Studio fits this description for a number of reasons. First, Visual Studio offers a very rich code-editing solution. It includes features such as source code colorcoding and code completion.
What is Silverlight 4 COM+ Automation support?
Second, it offers an integrated debugger, which allows you to place breakpoints in your source code to stop execution at any given point, as well as step through the source line by line, analyzing the state of objects and fields at any given point in the execution. Add to these features rich support for application deployment, installation, and integration with database services, and you can understand how Visual Studio is an extremely valuable tool for developers.
Support for Multiple Monitors Today it is common for developers to have multiple monitors attached to their development workstations and, unfortunately, previous versions of Visual Studio never took advantage of this extra real estate. Developers could use the extra screens for other applications, but often it would be nice to be able to view more than one source file at once. Visual Studio adds support for multiple monitors by allowing developers to pull source files, windows, and more out of the Visual Studio primary IDE and move them to other monitors.
Take, for example, Figure Visual Studio is open on the left monitor, and we are viewing the MainPage. However, I would like to inspect the class that my UI is bound to at the same time. To do so I can simply drag the class out of the docked position in the IDE and move it to the second monitor. I could do the same thing for the toolbox, the properties window, or any window within Visual Studio A very nice new feature!
One of these enhancements is the ability to zoom in and out of the source code editor. This will allow you to simply use your mouse scroll wheel to zoom into your source code. This is especially useful during presentations; however, there are times where developers could benefit from the ability to zoom in and out. For example, if you want to see a bigger portion of your source, you can zoom out and see your source from a greater distance, as shown in Figure When it is gone, you really notice how much you take it for granted and you find how dependent you really have become on it.
Well, as great as IntelliSense is, in Visual Studio it just got better. The addition of partial string matching allows IntelliSense to more intelligently display entries based on what the developer has typed. Improved IntelliSense in Visual Studio In addition to the partial string matching, the performance of IntelliSense has been dramatically improved. This allows developers to code without delays in IntelliSense and keep their rolls rolling. Add References Performance In Visual Studio and previous versions, developers have noticed that when you open the Add Reference dialog see Figure , it takes quite a bit of time for it to full display the listing of components, especially for the COM components.
In Visual Studio , the Add Reference dialog has undergone many performance improvements, which will help prevent developers form having to wait on the Visual Studio IDE. Add Reference dialog Reference Highlighting When you click anywhere within a symbol class name, variable, object, field, etc , all instances of that item are highlighted throughout the current document, as shown in Figure This is not a simple text matching; the editor is smart enough to understand the scope of the different variables.
So even if you have two items with identical names that belong to different objects, they are not both highlighted. You can easily navigate between the different highlighted instances as well by pressing Ctrl-Shift-Up to move to the next instance, or Ctrl-Shift-Down to move to the previous instance. In Visual Studio you can hold down the Alt key and drag a box around just the public declarations, as shown in Figure Box selection in Visual Studio Better yet, once you have this box selected you can edit all of the lines at once. So with the selection made, simply type private and it will automatically replace the public in each of the lines, as shown in Figure Editing a box selection in Visual Studio Call Hierarchy Window The Call Hierarchy window displays two lists regarding a given member: First all calls to the member incoming and all calls from the member outgoing.
Within each of those lists, you can then drill into each member and see its incoming and outgoing calls, forming a very useful call hierarchy.
To open the Call Hierarchy window, simply right-click on any method, property, or constructor and select View Call Hierarchy. An example of the Call Hierarchy window is shown in Figure Consider the following line of code calling the method SomeMethod that did not exist, and passing it an integer and a string: Person. Extension Manager Managing extensions and controls has always been a stressful point with Visual Studio and previous versions of Visual Studio. In Visual Studio the Extension Manager has been introduced. It allows you to easily browse an online library for different extensions as well as manage the extensions that are installed in your current development environment.
The Extension Manager is shown in Figure I personally hate the Hello World sample, but it is used often because it is so simple and provides a good introduction. Who am I to break with tradition? In the New Project dialog box, select Visual C as the project type, and in the list under that type, choose Silverlight. Select Silverlight Application as the template and name the project HelloWorld, as shown in Figure Then click OK.
Creating a new Silverlight project 3. It offers the choices of hosting the Silverlight application in a web site or within a project. Web, as shown in Figure See the next section for more information about choosing whether to use a web site or Web Application project for your own Silverlight applications. Notice that there are two projects created within your solution: one called HelloWorld. Web and one called HelloWorld, as shown in Figure Visual Studio has already opened the MainPage. Add the TextBlock within your Canvas object, as follows: 5.
Save the project and run it by pressing F5. The result should be as shown in Figure Your first Silverlight application in Visual Studio 6. In the code behind, you will notice a constructor for your Page class, which contains one method called InitializeComponent. Rebuild the application and run it again. Your result should look like Figure The final result from our first Silverlight application in Visual Studio 8. Close the application. There you go! You have built your first Silverlight application. Of course, this application is extremely simple, but you did get an idea of how things work in Visual Studio In Visual Studio , should you use a web site project or a web application project to host your Silverlight application?
The main difference between a web site project and a Web Application project is how the files are compiled and deployed. Each has its advantages and disadvantages. In the end, the choice pretty much comes down to user preference. There is no project file. Instead, the site simply contains all the files under the specific folder, including all text files, images, and other file types. A Visual Studio web site is compiled dynamically at runtime. Rather, you must browse to the folder after opening Visual Studio. To accommodate those developers, Microsoft announced the Visual Studio Web Application project as an add-on to Visual Studio In Visual Studio and , this project type is once again a part of Visual Studio.
A disadvantage is that it can be more difficult to share your solution with others, if that is your intent. In the end, both approaches have their pros and cons.
Pro Silverlight 4 in C#
You need to determine which one is more suitable for your application, depending on your specific purpose and goals. For more information about these project types, refer to the MSDN documentation. In addition, you built your very first Silverlight application. In the next chapter, you are going to start to dive into some of the Silverlight controls, beginning with the layout management controls.
These controls enable you to lay out your Silverlight applications. In this chapter, you are going to start to dive into some Silverlight development by looking at the layout management controls. Layout management involves describing the way that these objects are arranged in your application. You will take a look at each of these in-depth. By the end of this chapter, you should have a good understanding of when to use which layout control. Layout Management Silverlight provides a very flexible layout management system that lets you specify how controls will appear in your Silverlight application.
You can use a static layout as well as a liquid layout that allows your layout to automatically adjust as your Silverlight application is resized in the browser. Each of the five layout controls provided in Silverlight has its advantages and disadvantages, as summarized in Table Table Very simple layout. Requires that every control have a Canvas. Top and Canvas. Left property attached to define its position on the canvas. Allows for a quick dynamic layout.
Nesting StackPanel controls can provide some interesting layouts. The layout is limited to stacks of items. Spacing is limited to adding margins to the individual controls and to adjusting the alignment with the VerticalAlignment and HorizontalAlignment properties. The most flexible and powerful layout control. You can define just about any type of layout using the Grid control.
Grid definitions can get somewhat complex at times. Nesting Grid components can be confusing. Very similar to the StackPanel, except the WrapPanel automatically wraps items to a second row or column so it is ideal for layouts containing an unknown number of items. Limited control of layout as wrapping is automatic when items reach maximum width or height. Provides an easy way to create basic layout, consuming the entire application space in vertical or horizontal panels. The Canvas Panel The Canvas panel is a basic layout control that allows you to position Silverlight objects using explicit coordinates relative to the canvas location.
Left and Canvas. The XML attached properties Canvas. Left allow you to position the Canvas. Allow Visual Studio to create a Web Application project to host the application. When the project is created, you should be looking at the MainPage. Within the main Grid element, add a Canvas element. Assign it a Width property of and a Height property of In order to see the Canvas panel in the application, also set the background color to green. It contains only a single green rectangle positioned at the very center of your application, as shown in Figure Default Canvas with a green background 3.
Add the following code to place the button, which has the label Button1, a Width property of , and a Height property of The Button control is covered in detail in Chapter 4. Figure shows the button within the canvas. Single button within the canvas 4. Left as attached properties. Give this button the label Button 2, as follows: At this point, you now have two buttons within the canvas, but at different locations, as shown in Figure This is still not very exciting, but this is about as cool as it gets with the Canvas.
Two buttons positioned relative to the canvas 5. Go ahead and run the solution to see the end result as it will appear in the browser. The output is shown in Figure In some cases, you may wish to set the width and height of your Silverlight application within the browser. At other times, however, you will want your Silverlight application to take up the entire window of your browser, and to resize as the browser is resized. This is done very easily within Silverlight. It will resize as the browser resizes.
It can be used very effectively in a fixed layout. However, in most cases, you will want to use a static layout for your applications. The StackPanel control provides a more fluid layout control. The StackPanel control allows you to position Silverlight objects in more of a flow layout, stacking objects either horizontally or vertically.
Figure shows the basic concept of this layout control. When the project is created you should be looking at the MainPage. Within the main Grid element, add a StackPanel control and also three buttons with the labels Button 1, Button 2, and Button 3. Give all three buttons a width of and a height of Notice that the buttons are stacked vertically. This is because the default stacking orientation for the StackPanel control is vertical. The StackPanel control with horizontal orientation 2. Notice that all the buttons are touching each other, which is unattractive.
You can easily space them out by using their Margin property. Other options for HorizontalAlignment include Left, Right, and Stretch which stretches the content to the left and right. Make the following changes to adjust the buttons: After you have made these changes, your buttons are spaced out nicely in the center of the application, as shown in Figure The StackPanel control with buttons spaced apart and centered Try It Out: Nesting StackPanel Controls Microsoft designed the control framework so that any object can be contained within another object.
One way you can enhance your layout is by nesting a layout control within another layout control. In this example, you will nest a StackPanel control within another StackPanel control, but realize that you can nest any layout control within any other layout control to get the exact layout functionality you are seeking. In the MainPage. Here is what the updated source looks like: The cool result of this code is shown in Figure Nested StackPanel controls 3.
Run the application to see the results. As you can see from these two exercises, the StackPanel control is a very useful layout option, and you will probably use it often in your Silverlight applications. By nesting Silverlight controls, you have a lot of flexibility when designing your applications.
However, in the event that you want more control of the positioning of items in your application, without needing to resort to the absolute positioning used by the Canvas control, the Grid control may be just the layout option you need. As a comparison, you can think of using the Grid layout control as similar to using table elements to position items in HTML, only more flexible. With the Grid control, you can define rows and columns, thus creating grid cells, and then add objects to individual cells in the grid or to multiple cells, by using spanning.
To specify in which cell to place an object, you use the Grid.
hezogomo.tk: VB - Programming / Web Development & Design: Books
Column and Grid. Row attached properties. Note that these properties are base zero, so the top-left cell it is row 0 and column 0. Figure illustrates the row and column locations for the grid. Row and column grid cell locations in the Grid control layout For most developers, the Grid control will most likely be the layout option of choice, due to its flexibility. For this example, you are going to need a bit more space in which to work. In order to better see what is going on, turn on the display of grid lines by setting the ShowGridLines property to true.
The following code shows these additions. Keep in mind that since you have not designated a size for the grid, it will automatically take up the entire size of the parent, and in this case, the entire Silverlight application. Next, define the rows and columns in the Grid control. RowDefinitions and Grid. The asterisk tells the row and column to take up all available space. As the Grid control is resized with the browser window, those columns will be resized to take up all the space not consumed by the fixedsized columns.
After you have added these row and column definitions, your canvas should appear as shown in Figure We can also set the height and width using star sizing, which indicates that the value will be expressed as a weighted proportion of the available space. Grid with columns and rows 4. You can now add objects to the different grid cells. The grid with buttons in the four corners Try It Out: Nesting a Grid and Spanning a Column Next, you will nest another Grid control in the center cell of the Grid control you just added.
This will make the application layout somewhat complex, but it will also serve to show how Grid panels are defined using XAML. Now, this is a pretty cool layout. In order to do this, add the new button to the Grid control with the Grid. ColumnSpan attached property set to 2. Notice how the button spans the two columns and appears in the center. For experienced HTML developers who are used to laying out their forms with tables, this approach should be very comfortable, as it closely mimics using the colspan attribute for a tag. Final application with a nested grid and buttons In this example, you saw how to create a relatively complex layout using the Grid control.
As you can see, this is a very powerful and flexible layout tool for your Silverlight applications. It is very similar to the StackPanel control with one major difference: when items in a WrapPanel will not fit within the width or height of the control, they automatically wrap to a new row if horizontal orientation or column if vertical orientation. This makes the WrapPanel ideal for laying out an unknown number of items as they will automatically wrap to take up the entire space of the control.
As an example, if you look at Figure you will see how the WrapPanel will handle placing six items when set to horizontal and vertical orientation. Horizontally, the WrapPanel will place the items one after the other to the right, until no other items can fit within the width of the control. At that time, it will start to place the items in a new row directly below the first row.
The same is true for vertical orientation except the items are stacked below the previous item until new items cannot fit within the height of the control, at which time they will be place directly to the right of the previous row. The WrapPanel control orientations Try It Out: Using the WrapPanel Control In this exercise, we will explore the WrapPanel control and how it can be used to display an unknown number of items in stacks vertically and horizontally.
Allow Visual Studio to create a Web Application to host the application.
Series: The Expert's Voice
When the project is created, the file MainPage. We are going to add two rows to the root Grid control and then we will place a WrapPanel in the first row and a button with the label Add New Item in the second row. The WrapPanel is not part of the core Silverlight control set, but rather it is part of the Silverlight Toolkit. Because of this, you need to make certain you have the Toolkit downloaded and installed.
That way Visual Studio will automatically add the Xml namespace to the page. When the WrapPanel is first added, you will notice that it has some properties set that we may not want set. We do not need the HorizontalAlignment, Margin, VerticalAlignment, or Width property set, so we can either delete these properties manually in the source or we can use a new feature in Visual Studio to assist.
Now we need to add the code behind the button click event. FromArgb , 0, 0, 0 ; wrapPanel1. We can now test the application. Once the application appears, start pressing the Add New Item button and watch the items appear horizontally as well as wrap to a new row when a new item cannot fit within the width of the control see Figure Completed Horizontal WrapPanel 5. This time you will notice that the items appear vertically and wrap to new columns once they reach the maximum height, as shown in Figure It provides the ability to dock controls in all four directions: top, bottom, right, and left.
Consider Figure , which is a possible layout with the DockPanel control involving five controls. The first two controls are docked in the left panel; the third control is docked in the top-center panel; the fourth control is docked in the bottom-center panel; and the fifth control is docked in the right panel. Possible layout with the DockPanel To achieve this layout without the DockPanel would involve nested layout controls or a fairly complex Grid control.
The point is that the for certain situations the DockPanel can definitely be a very effective control. Try It Out: Using the DockPanel Control In this exercise, we will explore the DockPanel control and how it can be used to layout controls docked in different directions. This book covers key business intelligence design concepts and how they can be applied without an existing BI infrastructure. Author Bart Czernicki provides you with examples of how to build small BI applications that are interactive, highly visual, statistical, predictive-and most importantly-intuitive to the end-user.
Business intelligence isn't just for the executive branch of a Fortune company-it is for the masses. Let Silverlight 4 Business Intelligence Software show you how to unlock the rich intelligence you already have. Product details Format Paperback pages Dimensions x x Illustrations note XXVI, p.
Other books in this series. Add to basket. Beginning Silverlight 5 in C Robert L. Beginning Silverlight 4 in C Robert L. Introducing Silverlight 4 Ashish Ghoda. Silverlight Recipes Jit Ghosh.
Beginning Silverlight 3 Robert L. Table of contents Business Intelligence 2. About Bart Czernicki Bart Czernicki has been playing around with computers since and has spent years as a professional in the information technology field. He currently works as a senior software architect at a software development company.