navigate site menu

Start learning with our library of video tutorials taught by experts. Get started

Building Your First Windows Store App with XAML and Visual Basic

Building Your First Windows Store App with XAML and Visual Basic

with David Gassner

 


Microsoft Windows 8 introduces Windows Store apps (formerly known as Metro apps), which can be built with a variety of programming languages. In this course, David Gassner shows you how to pair XAML with Visual Basic to build a simple data-driven application. He provides a tour of the free Visual Studio 2012 Express for Windows 8 and runs through a few Hello World exercises before demonstrating how to perform most of the basic app programming tasks with XAML and Visual Basic. The course describes how to acquire and display data, add an app bar, and use Windows 8 contracts to share assets with other applications.
Topics include:
  • Installing Visual Studio 2012 Express for Windows 8
  • Testing apps with the Windows 8 simulator
  • Defining a split-page layout with XAML
  • Retrieving and parsing XML files with asynchronous programming
  • Displaying data with dynamic bindings
  • Sharing data with other apps through contracts
  • Displaying command buttons in an app bar
  • Creating Live Tile notifications

show more

author
David Gassner
subject
Developer, Desktop Apps
software
Windows 8, Visual Studio 2012
level
Beginner
duration
1h 48m
released
Mar 15, 2013

Share this course

Ready to join? get started


Keep up with news, tips, and latest courses.

submit Course details submit clicked more info

Please wait...

Search the closed captioning text for this course by entering the keyword you’d like to search, or browse the closed captioning text by selecting the chapter name below and choosing the video title you’d like to review.



Introduction
Welcome
00:05My name is David Gassner, and I'd like to welcome you to Building Your First
00:09Windows Store App with XAML and Visual Basic.
00:13In this course, I'll show you how to install the free Visual Studio Express
00:182012 for Windows 8, and how to create a new application using one of the
00:23included templates.
00:25Then I'll describe how to use Visual Basic's new asynchronous programming model
00:31to retrieve and parse an RSS feed from the Web, how to display the feed's data
00:36in a dynamic screen that's laid out with XAML, and controlled with Visual Basic,
00:42and how to integrate new Windows 8 features, such as the app bar, the share
00:47contract, and live tiles.
00:51This course just touches the surface of what's possible in Windows Store apps,
00:56but I hope it will help you get started building your own apps for this
01:00new platform.
Collapse this transcript
What you should know before watching this course
00:00Windows Store apps for Windows 8
00:03are built with a set of technologies and programming languages that are already
00:07familiar to many developers.
00:09At the core is the operating system,
00:12represented in this diagram by the Windows Kernel Services.
00:16Then there's a set of libraries called the application model
00:20and then the libraries that you call directly, the WinRT APIs.
00:25Regardless of which programming language or languages you use,
00:29you'll be working with these APIs in Windows Store apps.
00:32If you're a web developer, you might have chosen HTML and JavaScript.
00:37But if you're watching this course you've likely decided to go with XAML and Visual Basic.
00:43When you're trying to decide which programming language or languages to use,
00:47I recommend starting with something you're already familiar with.
00:50If you use Visual Basic, C#, or C++ and you want to use those languages,
00:56you'll be using XAML, or Extensible Application Markup Language, to define
01:01your screens or layouts,
01:03and then you'll be using your favorite programming language as the code behind language,
01:09and that's where you put all of your programming logic.
01:12Visual basic has the advantage of having been around for years,
01:16and many developers already know the language and are ready to use it in this new environment.
01:22For C+#or Java developers, C# offers a managed code environment, with C-like syntax.
01:29And if you have to achieve the best possible performance and you need strong
01:33graphical presentation, you should check out C++.
01:38You'll get that great performance
01:39and support for the DirectX graphical programming interfaces.
01:44Regardless of which programming languages you use,
01:47you'll be using Visual Studio 2012 to build your Windows Store apps.
01:52You can choose from one of the fee-for-license editions listed here,
01:56or you can use the free version, Visual Studio 2012 Express for Windows 8,
02:02and that's the version of Visual Studio that I'll be using throughout this course.
02:06If you'd like to learn a little bit more about the languages and technologies
02:09used in this course, check out these existing lynda.com courses. For more about this XAML
02:15watch Silverlight 5 Essential Training. Silverlight and Windows Presentation Foundation, or WPF,
02:23both use XAML as their presentation language.
02:26If you learn how to use XAML in one environment,
02:29you've learned a lot of what you need to know for another environment.
02:32And to learn more about Visual Studio,
02:35checkout Visual Studio 2010 Essential Training.
02:39Both of these courses teach skills that you might find valuable
02:42as you learn how to build Windows Store apps with XAML and Visual Basic.
02:46
Collapse this transcript
Using the exercise files
00:00This course includes exercise files that you can use to follow along as
00:05you watch the videos.
00:06I've placed the Exercise Files on my Desktop,
00:09but you can put them anywhere on your hard disk.
00:13The exercise files are created as Visual Studio projects that you can open up
00:18in Visual Studio Express 2012 for Windows 8, or in any pay for license version
00:24of Visual Studio 2012.
00:27To open one of the exercises, go to the chapter for that exercise.
00:31For example, I will go to 01_GettingStarted, to HelloWorldComplete, and look
00:38for the solution file.
00:39Double-click the solution file, which you can identify by the Visual Studio icon,
00:44and the project should open in Visual Studio.
00:48If you have more than one version of Visual Studio Express installed, you might
00:53be prompted to choose the one you want to use.
00:55Make sure you choose Visual Studio Express 2012 for Windows 8.
01:00After opening the project, I recommend rebuilding it.
01:03This will clear any errors that might occur from moving files around.
01:08Go to the menu, and choose Build > Rebuild Solution,
01:13and you should see output in the Output panel that indicates that the rebuild succeeded.
01:19Then you can run the application by going to the menu and choosing Debug > Start
01:25Debugging, or Start Without Debugging.
01:28There are keyboard shortcuts associated with both operations;
01:32F5 to debug, and Ctrl+F5 to start without.
01:37I'll run without debugging, and that installs the application, and runs it.
01:42After running the application, if you want to close it completely, press Alt+F4.
01:47That will take you back to the start screen.
01:50Then press Alt+Tab to move back to Visual Studio.
01:54To uninstall an application, go back to the start screen, scroll over and find
02:00the tile for the application, right-click on it to select it, choose Uninstall
02:06from the app bar that appears, and confirm.
02:09You should then be able to remove the application from your hard disk
02:12completely, or make any other changes that you like.
02:16The Exercise Files also include a Solutions folder.
02:19Here, you'll find finished versions of each application, and it's possible to
02:25open up more than one instance of the same application in two copies of Visual Studio.
02:31In the Solutions folder, for example, I'll go to the HelloWorldComplete folder
02:35there, double-click that solution, and now I have two copies of Visual Studio,
02:41with the two different versions of the project.
02:44I can then lay them out side by side by dragging and snapping them into place,
02:50and then you'd be able to compare code in two different versions of a file.
02:55By using these exercise files, and following along with the code, you'll be able
02:59to understand better how the code works, and how you can apply these lessons to
03:04building your own Windows Store apps.
Collapse this transcript
1. Getting Started
Installing Visual Studio 2012 Express for Windows 8
00:00To get started building Windows 8 Store apps, install Visual Studio Express
00:072012 for Windows 8.
00:08This software is completely free.
00:10I'm starting at my Windows 8 Desktop, and I'll go to Internet Explorer.
00:15From there, I'll navigate to dev.windows.com.
00:19That takes me to the Developer home page.
00:21From there, I'll click the Downloads link, and then, under Download the tools and
00:26SDK, I'll click Download now.
00:29That brings up a prompt at the bottom of the screen, and I'll click Run to
00:33download and run a very small starter application.
00:37Most of what you need will be downloaded during the installation.
00:41When the installer first starts up, it asks you to agree to the license terms.
00:46After checking the appropriate checkbox, you'll see an Install link at the bottom.
00:50Click the link, and then after responding to the user account control dialog, the
00:55installation will begin.
00:58The installation will take a quite a bit of time.
01:01In addition to downloading and installing Visual Studio, Windows will create
01:06a system restore point that will allow you to back up to this point on your Windows computer.
01:11After the system restore point, the rest of the download and
01:15installation continues.
01:17This would be a good time to pause the video, because the installation will take
01:21quite a few minutes.
01:24Once the installation is complete, you'll see this screen, with a link that lets
01:28you launch Visual Studio Express.
01:33When Visual Studio Express first opens, it will display in a dark background.
01:39If you'd like to change it to a lighter background to match previous versions of
01:42Visual Studio, go to the menu, and choose Tools > Options, and then on the General
01:50panel, change the Color theme from Dark to Light.
01:55Click OK, and now you'll be ready to create your first Windows 8 Store app.
Collapse this transcript
Hello World with XAML and Visual Basic
00:00Just as with any new technology, the first step in learning how to program a
00:05Window Store application is to create a hello world app; an application that
00:10simply outputs some text to the screen.
00:13I'm working in Visual Studio Express 2012 for Windows 8, and I'll create a new project.
00:19If you see the Start page, you can click on the New Project link, or you can
00:23always go to the menu and select File > New Project.
00:27The New Project dialog offers templates for the four supported programming
00:31languages: JavaScript, Visual Basic, Visual C#, and Visual C++.
00:37If you choose JavaScript, you'll be laying out your pages using HTML.
00:42If you choose any of the other three languages, you'll be working with XAML,
00:47Extensible Application Markup Language; the same markup language that's used in
00:52Silverlight, and WPF-based desktop applications.
00:56I'll choose Windows Store for Visual Basic.
00:59Then I'll set my application Name as HelloWorld.
01:04By default, the new application will be placed in a folder of the same name
01:09underneath the selected location.
01:11I'll click Browse, and I'll start off at my Desktop. From there I'll go to the
01:17Exercise Files folder to 01_GetttingStarted.
01:19I'll select that folder as the parent folder, and then I'll click OK, and that
01:27will create the project, and the application.
01:30When the project first opens, you'll see that the default page is
01:33called App.xaml.vb.
01:36This is the code behind file that contains the logic that goes with a XAML-based
01:42page, and the name of that page is App.xaml.
01:46If you double-click that file in the Solution Explorer on the right, you'll
01:50open it to XAML code.
01:51A XAML file is an XML file.
01:55The root element of the app file is always application, and it's the high level
02:00container for your application, but it's not the page the user actually sees.
02:06Instead, that file is called MainPage.xaml, and you can double-click to open it.
02:12When you first open MainPage.xaml, you should see this split display, with the
02:18design environment at the top, and the code view down at the bottom.
02:22You can swap the two panes back and forth by clicking on this icon, and then the
02:27code is at the top, the designer at the bottom, and click to switch back again, and
02:32you can hide either pane by clicking on the collapse icon here.
02:36So now I'm only looking at the design environment, and then I can click on the
02:40tab at the bottom for XAML, and I see the equivalent code.
02:44To output simple text in a XAML page, you use a visual control, and I'm going to
02:50add a visual control in Design mode,
02:52so I'll click the Design tab at the bottom. Then I'll go over to the left side
02:57of the screen, and I'll click the Toolbox tab.
03:00When the Toolbox opens, it shows a list of common XAML Controls at the top, and a
03:06listing of all available XAML Controls at the bottom.
03:09I'm going to click and drag a TextBlock control.
03:12You use a TextBlock to display text.
03:16I'll click and drag it on to the page, and when I release the mouse button, the
03:21toolbar snaps into its hidden spot.
03:23Now, with the TextBlock control still selected, I'll go to the Properties
03:28panel over on the right, and I'll scroll down to the Common category, which
03:33should already be open.
03:34I'll change the text that the TextBlock is displaying from TextBlock to Hello World.
03:42When I press Enter, that results in displaying the text in the
03:46Design environment.
03:47Now, I'm going to change the font settings.
03:50When you first create a TextBlock, it will come out in this very small font, but
03:55I'll go to the Properties panel, I'll close the Common category, and I'll go to
04:00the Text Properties category.
04:03I'll scroll down a bit, and then I'll pull down the list of available fonts.
04:08The standard recommended font for Windows Store apps is called Segoe UI.
04:14I'll scroll down to the Segoe section, and then select Segoe UI.
04:19Then I'll change the size of the font from 11 pixels to 50 pixels.
04:25And now that font looks like something similar to what I might have seen in
04:29other Windows Store applications.
04:32Next, I'll place the control in its recommended location.
04:36The Windows 8 Design Guidelines say that the heading for a page should be 120
04:42pixels from the left side of the screen.
04:44I'll close the Text category, and go to the Layout category.
04:49I'll go down to the margins, and I'll change my left margin from whatever it
04:54shows here -- the actual number will depend on where you dropped your control -- to
04:59120, and that places the object 120 pixels from the left.
05:04Next, I'll move the object up.
05:07I'll talk more in a later video about the recommended specific location of this
05:12control, but for now, I'll just set the top margin at 45.
05:17So now my page is looking about the way I want it, and I'm ready to launch it
05:22for the first time.
05:23To launch the application, go to the menu, and select Debug.
05:28There are options to Start with Debugging, and Without Debugging.
05:32Typically, you'll get better performance by starting without debugging, so you
05:36can either select that menu option, or press Ctrl+F5.
05:41When you launch without debugging, that results in installing the application
05:46into your operating system, and then launching it for the first time.
05:50The application will now take up the entire screen.
05:53That's the nature of a Windows Store app.
05:55Now I'll go to the Start screen, and scroll way over to the right, and show that
06:01my application was installed, along with a tile that's automatically added to the Start screen.
06:07I can run the application from here by clicking on the tile.
06:10With the application open, if you want to close it completely, press Alt+F4.
06:16That will take you back to the Start screen, and then you can press Alt+Tab to
06:21return to Visual Studio.
06:23Now let's take a look at the XAML that was generated when I dragged the control
06:27in, and set its properties through the visual environment.
06:31I'll click on the XAML tab, and then I'll close the Output panel.
06:35Here's what the XAML code looks like.
06:38In a page XAML file, the root element, by default, will be Page, and then its
06:44class attribute will point to a Visual Basic class file that's associated with
06:49it as what's known as the code-behind file.
06:53You can get to the code-behind file in a couple of different ways.
06:57With the name of the class selected, you can right-click, and select View Code,
07:02or press Ctrl+Alt+0.
07:04If you select View Code, that will take you to the Visual Basic file, and this is
07:09where you would put in the logic that controls the behavior of that page.
07:14I'll close that file, and then go over to the Solution Explorer, and show that
07:20the file is available there too as an item under the MainPage.xaml tree.
07:25I can open up the tree, and then double-click to open the file again.
07:29I'll return to the XAML file, and point out a Grid control that's inside the page.
07:37Every page of a Window Store app uses XAML to lay out its objects using a grid.
07:43I'll show you some ways of using this grid in later videos, but it's important
07:47to know that you have to have the grid there, and all other visual controls get
07:51placed within the grid.
07:53Finally, the TextBlock control is placed within the grid.
07:57The TextBlock control has some properties that I set, such as the margins of 120,
08:02and 45, the text property of Hello World, and the font family, and size, but it
08:08also has properties that were added automatically by Visual Studio.
08:12I encourage you to go back into Design view, and try adding different kinds of
08:17controls from the Toolbox, and see what an application can look like,
08:22but in pursuit of the goal of building the simple application that this course
08:25is all about, I'll now go on to the next video, where I'll show you how to use
08:30styles to affect the look and feel of a font.
Collapse this transcript
Exploring design principles of Windows Store apps
00:01Windows 8 store apps follow a set of design principles formerly known as the
00:07Metro Design Language, but now simply known as Windows 8 Design Guidelines, or
00:12Modern Design Guidelines.
00:14These guidelines fall into six categories: Navigation, Commands, Touch
00:20interaction, Advertising and Branding, and User experience.
00:26Applications follow navigation patterns that range from hierarchical to flat.
00:31A hierarchical navigation design is one where you have a hub page, and then
00:37perhaps section and detail pages.
00:40You go from the first page, the hub, and drill down into your data.
00:44A good example of this is the Photos application that's included with Windows 8.
00:49In this application, you start with a set of icons indicating the location or
00:55source of your photographs.
00:57Then you can drill down into a section; from there, into a set of items, and from
01:02there, into the detail for a particular item.
01:05Then, when you click on the page, an icon appears that lets you go back
01:09through the hierarchy.
01:12Hierarchical applications are good for content systems; that is, collections of
01:17content, such as photographs, or news articles, or where your content can be
01:22defined into distinct sections.
01:24Another common navigation pattern is the flat application.
01:28A flat application has a single container that shows one page, or one display at a time.
01:35The most common example of this is the new version of Internet Explorer that you
01:40get to from the Windows 8 Start screen.
01:43I'll go to the Start screen, and fire up Internet Explorer, and I'll go to the
01:47Microsoft Website: microsoft.com.
01:51From there, I'll go to Google,
01:53and you'll see that you're replacing the content, but still staying within the same frame.
01:59Other examples of flat navigational applications include games, or document
02:05creation applications.
02:07For more information about navigation patterns, go to the Bing search engine, and
02:12search for this string: hh761500.
02:14I'll go to Internet Explorer, and type in that string, and automatically I'll be
02:23searching Bing for the string.
02:26From there, I can get to the documentation about navigation design for
02:30Windows Store apps.
02:32You'll find a lot more detail here, including useful diagrams showing different
02:37kinds of navigation.
02:39The next pattern that you should learn about is called the commanding pattern.
02:43A commanding pattern is how the user controls the application, and indicates what
02:49they want to do next, and where they want to go.
02:51Wherever possible, you'll want to handle navigation by using the content of your
02:57application. That is, instead of choosing an item, and then saying what you want
03:02to do with it, if possible, you should allow the user to express a user gesture
03:07directly with that content item.
03:09Going back again to the photos application, this is a great example.
03:14To get to a particular photo, I simply click on the content.
03:18I go down to the flowers, and then to a specific flower.
03:23So, I'm clicking and pointing at the thing I want.
03:26There's no additional chrome or user controls necessary with this sort of pattern.
03:31There are many common commands that are used by many applications, such as
03:36searching, sharing, managing external devices, and setting the configuration of the app.
03:43These functions should always be accessed through the charm contracts.
03:48The charms are accessed by moving the cursor to one of the hot corners on
03:52the right, either top or bottom, or on a touch device, by swiping in from the right side.
03:58For example, the Search contract gets you the search functionality for
04:03all Windows Store apps.
04:05A great example of this is the Store application.
04:09From the Start screen, I'll type the word store, and then press Enter, and that
04:14takes me to the start screen.
04:16Now, I can scroll around, and look at applications that I might want to purchase,
04:21but if I want to find a specific application, I might not find it by
04:26scrolling back and forth.
04:28Instead, I'll open up the Search charm.
04:31Let's say that I was looking for Evernote, a popular application for keeping
04:36notes that synchronize across multiple devices.
04:39I'll type evernote, and because I started at the Store app, I'm searching the Store app.
04:45I'll click, and that takes me to the detail for the selected item.
04:50If you're coming from a conventional Windows programming background, it's
04:54tempting to think that functions like searching, and sharing, and configuration
04:59should be a part of the main application user interface, but in Windows 8 Store
05:04apps, those are all handled through the charms.
05:07Finally, there's the app bar.
05:09The app bar is something over which you have complete control.
05:13It's a place where you can put buttons or icons that take users to particular
05:18actions in your application
05:19For example, I'll go back to the Photos application once again.
05:24With a detail photo selected, I'll right click, or if I'm on a touch device, I'll
05:30swipe from the top to bottom, and that takes me to the app bar, which appears at
05:35the bottom of the application in the Photos app,
05:38and here I can control my photo.
05:40I can rotate it, crop it, delete it, and take other actions that are specific to photographs.
05:47For more on commanding patterns, search Bing for hh761499.
05:54There are also touch patterns to pay attention too.
05:58Most of the touch patterns you need are handled automatically.
06:02These include swiping, tapping, pressing and holding, sliding to pan, and
06:07pinching and stretching.
06:09Most of the functionality in your application will probably work just fine out
06:13of the box, but you'll want to test your application on a touch device, such as a
06:18Surface RT, or other device that has a touchscreen.
06:22For more on touch patterns, search the string hh465415.
06:25Finally, the overall user experience, including screen layout.
06:34Microsoft provides extensive guidelines for laying out your applications.
06:40The goal isn't to make all applications look the same.
06:42For example, while there are recommended typefaces, you don't have to use those
06:48typefaces. Instead, you should mix those typefaces with those that give your
06:53application strong branding.
06:54But you should be familiar with what's known as the grid layout, and the Windows
06:59silhouette; strongly prescribed locations of items on the screen that are
07:05common across applications, that make all Windows Store apps feel like they're
07:10a part of the whole.
07:11For more on user experience design, search for the string hh465424.
07:18The documentation you'll find there can help guide you through designing the
07:21best possible Windows Store app; one that will fit into the store, feel like
07:26a part of Windows 8, but also give your application the strong branding that
07:31you want.
Collapse this transcript
Applying themes and styles
00:00In my Hello World application, I used a TextBlock control, and applied a
00:05specific font and size.
00:07Now I'm going to do the same thing, but this time using styles.
00:12I'm working in a project called UsingStyles, which is available in
00:1501_GettingStarted, and I'll double-click on the solution file, which you can
00:20recognize by the Visual Studio icon.
00:22When the project opens, it takes me to MainPage.xaml in Design view.
00:29When you create a brand new application in Visual Studio 2012, by default, it
00:34will have a dark background and a light font color.
00:38Taken together, these attributes are known as the Dark theme, and a new XAML
00:43application has two themes that you can choose from;
00:46the dark theme, and the light theme.
00:49To change the theme, open the file App.xaml.
00:54That file always opens in Code view.
00:57Then place the cursor inside the beginning tag, and add an attribute
01:02called RequestedTheme.
01:04You'll see the two options; Dark, and Light.
01:07The default is Dark.
01:09If you want Light, you just have to select it.
01:12I'll save my changes, and then go to the menu, and select Debug > Start Without Debugging.
01:19And when the application opens, I see the light background, and the dark font face.
01:25I'll go back to Visual Studio, and go back to MainPage.xaml, and you'll see that
01:31the designer still is showing the older style,
01:34and that's because the design environment is sensitive to settings that are a
01:39part of the environment, not the application.
01:42To change this so that your designer looks the same as the application, go to
01:47the Device tab on the left.
01:49Notice the Theme is set to Default.
01:51You can change it to Light.
01:54You'll see that the design surface changes to mimic what you're going to see
01:58when the application really runs.
02:00Now, for the rest of this application, I'll be working in the Dark theme,
02:04so I'm going to switch it all back again.
02:07I'll go back to App.xaml, I'll change from Light to Dark, I double-clicked
02:12on the word Light to select it, then pressed Ctrl+Space to bring up the list of options.
02:19I'll choose Dark.
02:20I'll save my changes.
02:22I'll go back to MainPage.xaml to the Design view.
02:26I'll go again to the Device panel, and I'll change the Theme from Light to Dark.
02:32I'll save my changes, and I'll run my application again, this time pressing
02:36Ctrl+F5 to run without debugging,
02:41and my application is back to the Dark theme.
02:44A theme is nothing more than a collection of styles, and there are a number of
02:48predefined styles that are included with any new XAML-based application.
02:54You'll find these styles in a file called StandardStyles.xaml that's located in
02:58the common folder within the project.
03:01When you open StandardStyles.xaml, it will open in Code view, and if you try to
03:06look at it in Design, you won't be able to.
03:09Going back to the XAML view, I'm going to search for one of the predefined styles.
03:14I'll press Ctrl+F for Find, and I'll type in PageHeader.
03:19I'll press Esc to clear the Find Box, and now I can explore the styles.
03:25A style is declared using a Style element in XAML code;
03:29x:Key is the identifier,
03:32and that's how you'll use the style in your XAML code.
03:35XAML-based styles are very similar to cascading style sheets in a Web browser.
03:40Each style can have its own properties.
03:43This style has properties for text wrapping, vertical alignment, and margin,
03:47but it can also inherit properties from another style, and this is done through
03:52the BasedOn attribute.
03:54This style inherits from HeaderTextStyle,
03:57so any settings that are in that style, or any of its parent styles, will be reflected here.
04:03I'm going to use this style in the file MainPage.xaml.
04:07I'll click on the XAML file, and then click on the TextBlock that's
04:10outputting Hello World.
04:12In this version of the project, I don't have any specific font or size settings,
04:17and so it's showing the default.
04:19With the textbox selected, I'll go to the Properties panel, I'll scroll down, and
04:25select the Miscellaneous category, and here is the Style selector.
04:29I'll click on the square icon, which will open up a context menu, and I'll
04:34choose Local Resource, and here are all the styles that are defined in the
04:39standard styles file.
04:41And I'll choose this one: PageHeaderTextStyle,
04:44and that changes my TextBlock to the font and size that are the standard for all
04:50beginning applications.
04:52Now I'll take a look at the actual font and size that were selected.
04:56Going back to the Properties panel, I'll go to the Text category, and I'll see
05:01that this style implements a font-family of Segoe UI, and a size of 56 pixels.
05:08I'll save again by pressing Ctrl+S, and then run the application, and I'll see
05:13the change has taken hold.
05:15So, that's a look at how you can get started with themes and styles in a
05:18XAML-based application.
05:20This is exactly the same process regardless of whether you're working in
05:24Visual Basic, C#, or C++.
05:28In any XAML-based application, you can use styles and themes to manage the
05:32appearance of your app.
Collapse this transcript
Testing apps with Visual Studio and the Windows 8 Simulator
00:02Visual Studio 2012 gives you a few tools you can use to test your application
00:06without having to have a lot of different monitors and devices.
00:10The first and simplest way to test your application is on the same computer on
00:14which you're doing your development,
00:16and you do that simply by running the application from the Visual Studio menu.
00:21When you select Debug > Start Without Debugging, or press Ctrl+F5, you'll install
00:28and run the application.
00:30And then you can return to the Start screen, and you'll see that the
00:34application has been installed, and can be restarted from there.
00:39When you want to get rid of an application, close it first by pressing Alt+F4.
00:45Then you can go to the Start screen, right-click on it, and Uninstall it from
00:50the app bar icon that appears.
00:53When you confirm the request, the application will have been uninstalled from
00:57the operating system, but it's still there in Visual Studio.
01:01You might only have a single monitor connected to your development system,
01:05though, and so you need a way to see how your application will look and behave
01:10on other monitors, and on other devices.
01:14For simple design work, you can use the Device panel.
01:18The Device panel is only available when you're working in Design view on a XAML page,
01:24but from this panel, you can change the appearance of your design surface.
01:30The default is 1366 pixels wide by 768 pixels high.
01:37That's the size of a Surface RT device, and it's also the size that's declared
01:43in the documentation as the minimum for running applications side by side or in Snapped mode.
01:50When you look at your application in this view, you'll see approximately what
01:55it will look at on these medium-size devices.
01:58By default, your screen might be truncated, or cut off,
02:02but you can look at the entire screen by going to the Zoom selector in the
02:06lower left, and selecting Fit all.
02:11If you want to see what this XAML page might look like on a very large
02:14screen, you can go to the Device panel, and set the display from 1366 by 768 to
02:22perhaps 1920 by 1080.
02:23Then, once again, reset your Zoom to Fit all, and that's what it might look like.
02:31The Device panel has support for displays all the way up to 2560 by 1440.
02:37And once again, after you select each one, you'll need to reset your Zoom to Fit
02:42all to see what it will look like.
02:45What it looks like at design time is one thing, but how it behaves at run time is another,
02:50and for that purpose, Visual Studio includes the Windows 8 simulator.
02:55The simulator does exactly what it says.
02:58It simulates an actual Windows 8 device, and has support for rotating the device,
03:04and also for other features that might be used by a device user.
03:09To get to the simulator, go to the toolbar, and change from Local Machine to Simulator.
03:17After that, the first time you run an application, either with or without
03:22debugging, it will launch the Simulator application, which is included
03:27with Visual Studio.
03:30The Simulator application opens, and sizes to your monitor.
03:34It's actually running your copy of Windows 8,
03:38and so, if you click the Start button on the simulator to go back to the start
03:41screen, and then scroll over to the right, you'll see all the applications that
03:46you've previously installed or run.
03:49To get back to an application, just click on the tile, and then you can start
03:54playing with features of a device.
03:57These icons let you rotate the device.
04:00I'll rotate it clockwise, and see how my application adapts, and I'll rotate it
04:06again counterclockwise to return it to its original orientation.
04:11You can also use the hand icon to mimic touch.
04:14I'll click the hand icon, I'll come back here and click the Start button, and
04:21now I can click and drag, and see what would happen if I put my finger on the
04:25display, and simply drag back and forth.
04:30There are also tools for Pinch/zoom touch mode, and also for Rotation touch mode.
04:37There's also a feature you can use here to take a screenshot of your application.
04:43I'll click on the pointer to go back to Mouse mode, I'll scroll over to the
04:47right, and I'll restart my application; Hello World complete.
04:52Then I'll go to the icon, and click Copy screenshot.
04:56That takes whatever is in the Simulator, and copies it to the clipboard.
05:01From there, I'll go to my Start screen, I'll type word pad to open up a word
05:06processor, and then I'll paste my graphic into place.
05:11You can take this screenshot, and put it into documentation, or use it to show in
05:17the Windows Store what your application looks like.
05:20I'll close WordPad, and I won't save, and then I'll return to the Simulator.
05:26Once you've started debugging or testing with the Windows 8 Simulator, you can
05:30just leave it open, and this will save you time each time you make a change to
05:35your application in Visual Studio, and want to launch it again.
05:38So, I'll simply switch back to Visual Studio, and I'll click on my text block
05:43that says Hello World.
05:44I'll go down to my Common category in the Properties panel, and I'll change the
05:50text to Hello World Complete.
05:53I'll save my changes,
05:55and once again, I'll run the application.
05:59And because I had already run the Simulator, and left it open, the Simulator
06:03re-launches automatically, and comes to the foreground.
06:07If you want to get the Simulator out of the way, you can click on the Minimize icon,
06:12but you'll see that the Simulator does not have a close icon.
06:17Instead, to close it completely, go down to the taskbar, right-click on the
06:21Simulator icon, and select Close Window,
06:25and that will close down that Windows 8 session, and that copy of the Simulator.
06:30To go back to testing and debugging your application on your native computer, go
06:35back to the selector, and change from Simulator back to Local Machine,
06:40and now you're back to your beginning state.
06:42I'll once again run the application, this time by pressing Ctrl+F5, and now I'm
06:48running the application on my own system.
06:50So, you can use the combination of the Device panel for design time, and the
06:57Windows 8 Simulator for run time testing to see what your application might look
07:01like on a variety of screens and devices.
Collapse this transcript
2. Creating a Cloud-Connected Windows Store App
Creating a split-screen app project
00:02Visual Studio 2012 includes a couple of application templates that let you see
00:06how to build simple data-centric applications.
00:10One of these is called the Split Application template, and the resulting
00:14application is shown here.
00:16It displays data in groups.
00:19The main page, or the first page that's displayed, shows three groups of data.
00:24The user can then click onto one of the groups, and see the details, and there
00:29they'll see a list of data on the left, and detail data on the right.
00:33And when they click on one of the items in the list, they see the details
00:37displayed through bindings.
00:38I'll show you how to build this type of application using data that's
00:43acquired from a Web service.
00:45It's not going to be the complete application.
00:48Our application will have a single page displaying just a list, and the details,
00:54but by learning how to code this application, you'll get a good understanding of
00:58how data binding works in XAML-based applications.
01:02In Visual Studio, I've opened a beginning project. It's named SplitPage, and you
01:08can open the same project from Chapter 2 of the Exercise Files.
01:14In the beginning state of this application, there's a StackPanel containing two TextBlocks.
01:19In XAML, a StackPanel is used to lay out objects.
01:25You can have a StackPanel with an orientation of vertical or horizontal to
01:30lay out objects from top to bottom or left to right.
01:34This StackPanel has an orientation of vertical, and as a result, the two
01:38TextBlocks appear one above the other.
01:41I'm going to add the code you need to split the rest of the page in two parts
01:46vertically, so that there's a left column and a right column,
01:51and I'll do this using a component called a grid.
01:55I'll go back to the XAML view, and look at the page in full screen mode.
01:58The outer component is already a grid.
02:01Each XAML grid can be split into rows or columns.
02:07The outer grid of this page will be split into rows.
02:10The StackPanel will be the first row, and a split grid will be the second row.
02:16I'm going to add code above the StackPanel to define the measurements or
02:21dimensions of my rows.
02:23After the Grid tag, I'll add a tag set called Grid.RowDefinitions,
02:29and within the RowDefinitions, I'll add two RowDefintion objects.
02:35The first one will have a height of 180.
02:39That means 180 pixels.
02:41Then I'll add a second RowDefinition, and it will have a height of star, or asterisk.
02:47The star in XAML means everything else,
02:50so however tall the screen is that this application is displayed on, the first
02:56180 vertical pixels will be for the StackPanel, and the rest of the vertical
03:00space will be for everything else in the page.
03:03The StackPanel already has a Grid.Row attribute set to 0.
03:08That means the StackPanel is the Grid's first row.
03:12We use 0 to mean the first row, 1 to mean the second row, and so on.
03:17So, now the rest of my job is to define that second row of the vertical display.
03:22I'll place the cursor after the StackPanel, and I'll add a nested grid.
03:28I'll set its Grid.Row attribute to 1.
03:33Then I'll add some margin settings, so that the grid is a little bit narrower
03:38than the rest of the page.
03:40I'll set a margin of 40, 0, 40, 0, and that means that grid will stretch from 40
03:49pixels from the left side to 40 pixels from the right side.
03:53Now, my outer grid is separated into rows.
03:56My nested grid will be separated into columns, and
04:00to do that, I'll add a Grid.ColumnDefinitions tag set.
04:05That will be placed as the first element within the grid.
04:09And then, just us I did with the RowDefinitions, I'll create two
04:13ColumnDefinition objects.
04:17The first ColumnDefinition object will have a minimum width of 320 pixels.
04:24The second ColumnDefinition initially won't have any attributes.
04:28Now, if I leave this dimension attributes as is, the columns will actually show
04:33up as 50% each of the available space, but I want to carve them up a little bit differently.
04:40I'd like my first column to take up one third of the available space, but with
04:44a minimum width of 320 pixels, and my second column to take up two thirds of
04:49the available space.
04:50And to make that happen, I'll add width attributes to each one.
04:54The first one will be 1, asterisk, and then the second one will have width of 2, asterisk,
05:00and what I'm saying is that the first column is one third of the available space,
05:05and the second column is two thirds of the available space.
05:08If I were to set this at one and three, it will be 25% and 75%, and so on.
05:15I'll leave it at one and two.
05:17Now I'm ready to define the two columns.
05:20Each column of the grid has to be of visual component; a view of some sort.
05:26The view that I'll use for my first column will be a list view.
05:31Eventually, it's going to show data that I download from the Internet.
05:34I'll create a ListView tag, and I'll set its Grid.Column attribute to 0.
05:41This is just like setting the rows as I did before.
05:44Zero means the first column, one means the second column, and so on.
05:50And I'll set some margins.
05:52The ListView will have a margin of 25, 0, 0, 0.
05:57So, it will be inset from the left side of its parent container by 25 pixels.
06:03I'll also set its horizontal alignment to left,
06:07and that means that all of the object within the ListView will hug the left
06:11side of the parent grid.
06:13Then I'll type in a greater than character, and that auto-completes the End
06:17tag of the ListView.
06:18That's all I'm going to do on the ListView for the moment.
06:22Now I'm ready to create the second column.
06:25The second column will be another StackPanel.
06:28It will have a Grid.Column attribute of 1, so it will be the second column of
06:33my outer grid, and it will have a margin of 25, 0, 0, 0, and a horizontal alignment of left.
06:44Within the StackPanel, I'll add two TextBlocks.
06:48The first TextBlock will have a font size of 24 pixels, and it will have a
06:54placeholder Text of Title.
06:56Eventually, that will be filled in using a data binding.
06:59That is, a dynamic binding that adds dynamic values.
07:03I'll add a second TextBlock, and this one will have a font size of 14; a little
07:09bit smaller than the first one, at a Text value of Description.
07:13This TextBlock is going to contain longer prose, and I want it to eventually
07:19word wrap, so I'm going to add an explicit width of 500 pixels, and a
07:25TextWrapping attribute of Wrap.
07:29Now I'll take a look at the page in Design view,
07:32and I'll see that the title and description are over on the right, and there's a
07:36column over on the left as well.
07:39I can move the cursor over the object and see how they're laid out.
07:43Be careful not to click too much, because you might accidentally add rows and
07:48columns you really don't want.
07:50And now run the application by selecting Debug > Start Without Debugging, and
07:56that will install and run the application in the operating system.
08:00So, that's the begging of the application layout.
08:02We're ready now to go get some data, and I'll show you now to retrieve data from
08:08an Internet-based Web service in the next video.
Collapse this transcript
Exploring the app's data feed
00:01The application I'm building eventually will look like this.
00:05It'll have a list of data on the left, and detailed information on the right.
00:11The list will have names and photographs of artists, and the details will have
00:16the artist's biography and an image; one of their artworks.
00:19The user will be able to select an item, and see the information that they've
00:24selected on the right side.
00:26All of this data will come from a feed that's available on a public Web site on
00:31the Internet, and I'll show you where that feed is now.
00:36I'll go to my Desktop, and double-click a link that I've added there.
00:40Then, in the version of Internet Explorer that's available from the Desktop, I
00:44see the feed displayed. It's an RSS Feed.
00:49RSS is a common XML format that's used to share data over the Web.
00:54When you load it into the version of Internet Explorer that's included in the
00:58Desktop, it looks like this,
01:00but if you'd like to see the XML structure in a more raw format, copy that
01:05link to the clipboard. It's
01:07datafeeds.rouxacademy.com/rss/artists.xml.
01:16I'll copy that, then I'll go to my Start screen, and I'll open up Internet
01:20Explorer from there.
01:23I'll paste in that URL, and then, when prompted, I'll save the XML file to my
01:29Downloads folder, and then I'll click Open, and I see the actual structure of the
01:35XML file displayed, with a little bit of color coding.
01:40This is a standard RSS file. It has a channel element.
01:45Under channel, there is a title, description, and link, and then multiple items.
01:50Each item has a title, link, and description as well.
01:54I'll use all these information to populate my application with data and images.
02:01My job will be to take this data, and turn it into something that my store
02:06app can use, and I'll show you all the code you will need to do that in the
02:10next video.
Collapse this transcript
Asynchronous programming with Async and Await
00:00Regardless of what programming language you work in, or environment you're
00:04programming for, at some point, if you're working with data that's retrieved over
00:08the Web, you'll need to deal with the difference between synchronous and
00:11asynchronous programming.
00:13Synchronous programming means that you make a request on a single thread of your
00:18application, and then that thread pauses until the response comes back.
00:23While you're waiting for the response, the thread can't do anything else. It's blocked.
00:28This sort of programming works fine in a desktop environment where you have a
00:32single user, and where you have plenty of processing power, and multiple threads
00:37to work with, but in a mobile environment where you have less processing power,
00:42asynchronous programming dominates.
00:44In asynchronous programming, you make the request, and then the current thread is
00:48freed up to do other things.
00:51When the response comes back, you use some sort of programatic architecture to
00:55trigger code that will run only when the response is available.
00:59In Windows 8 store apps, you can only use asynchronous programming to make
01:04requests over the Web, or to create or read files on the local disc.
01:09Remember that Windows Store apps are built both for conventional computers,
01:13where you might have plenty of processing power, but also for lower power
01:17devices, such as tablets.
01:19So, to guarantee the best possible performance, you can only use asynchronous
01:24programming, and then while the request is active, the device will still be able
01:28to respond to user gestures, run animations, and do other things it needs to do.
01:34Older versions of Visual Basic supported asynchronous programming using
01:39architecture called a callback method.
01:41A callback method is a separate subroutine or function that you create to
01:46respond to and handle a request.
01:49Here is a greatly simplified code snippet that uses a callback method.
01:54Imagine that this code is a part of a larger class, and there is a variable code
01:59StringResult that's declared before any subroutines. Then, when the first
02:03subroutine is called, StartWebRequest,
02:06a request object is created, and then after a little bit of preparation, the
02:10request is sent off with the method BeginGetResponse.
02:14That method receives an instance of the separate class named here AsyncCallback.
02:21We're dealing with that subroutine as an object; a callback method.
02:25When the response comes back from the remote server, the code within the
02:29callback method is executed.
02:31Again, I've simplified this enormously, and the amount of code we have to write
02:36using callback methods can be fairly complex, and hard to maintain.
02:40In Windows 8 store apps, and in .NET Framework 4.5, you can use a newer style of
02:47programming that uses two words called Async, and await.
02:52Now, again, this architecture is only available starting in Visual Basic 11; the
02:57version of the language that's used in Windows 8.
03:00Here is the code I now need to write to make an asynchronous request over the Web.
03:05I've created a function that I've named GetFeed, and it returns an instance of an
03:10object called a task.
03:12A task is a wrapper around any data type that you need to return from an
03:17asynchronous method.
03:19I'm saying that my task contains a string, and then I've marked this method
03:24GetFeed with the keyword Async.
03:27Typically, the Async keyword goes after the access modifier; in this case, the word private.
03:33Now, within the method, I can make an asynchronous request, and I'm doing that
03:38using a class called HttpClient.
03:40I create a variable indicating where my data is, then I create my client object,
03:46and then I call the client objects GetStringAsync method, and I place the keyword
03:51Await before the call to the method.
03:54The Await keyword means wait for the response; don't do anything until the
03:59response comes back. But more importantly, it frees the current thread to go do
04:05other stuff while it waits.
04:07When the response comes back from the remote server, this thread picks up and
04:11continues executing, and you can add as much code after the call as you need to.
04:16In this example, I'm just returning the string value as a response.
04:21So, where you might have needed a dozen or more lines of code using callback
04:25methods, using Async, and await, you can enormously simplify your code, making it
04:31more readable, and easier to maintain.
04:34So, in the following videos, I'll show you how to use these new features of
04:39Visual Basic to make a remote request over the Web to retrieve an RSS feed,
04:45parse it, and provide that data to a Window Store app.
Collapse this transcript
Retrieving, processing, and RSS data feeds
00:00In a previous video, I described where the data for this application would come
00:04from; an RSS Feed on a public Web site.
00:08I also described conceptually how asynchronous programming is done with Visual Basic.
00:13Now we'll put the two things together.
00:15I'm working in a version of my project called RetrieveData.
00:19In this version of the project, I've added three new classes.
00:22They're named ArtistItem, ArtistData, and ArtistDataSource. Let's look at
00:28them one at a time.
00:29I'll start with ArtistItem.vb.
00:32In my application, each artist is going to require four data elements;
00:37the artist name, a picture of the artist, a picture of their artwork, and their biography.
00:43Each of these four values will be a string, and I've modeled this data entity
00:49using this class ArtistItem.
00:51Each property is set up as a public property, with an explicit getter, and setter.
00:56The getter is returning a private variable called ArtistName, and the setter
01:00is setting that value.
01:02I've modeled all four properties in exactly the same way.
01:06Next, let's take a look at the class ArtistData.
01:09This is going to be a higher level class that contains a list of artist objects,
01:15but also has a couple of values that are for the entire application.
01:19Just as with ArtistItem, there are a couple of public properties with an
01:23explicit getter, and setter; the title, and the subtitle.
01:28Then down towards the bottom, there is a list of the ArtistItem class.
01:33The list class in Visual Basic is an ordered collection.
01:37It keeps data in the same order in which it's put into the data.
01:41The items property is a list of artist items, and once again, it has an
01:45explicit getter, and setter.
01:47The explicit getter is particularly important for all of these classes.
01:52It's what allows you to bind data to a visual interface to find with XAML code.
01:57We'll get to that binding architecture later on in the course, but for now, I'll
02:01just say that when you're modeling your data, you want to use these explicit
02:05getters, and setters, and private properties.
02:08Now let's take a look at ArtistDataSource.
02:11The job of the ArtistDataSource class is to actually make the request, and
02:15process the response, and then to take the raw RSS feed, and turn it into the data
02:21in the form we need it.
02:22Let's look at the RSS DataSource one more time.
02:25The channel element has properties called title, description, and link, and
02:30then there are multiple item elements, each of which also has a title, link, and description.
02:35We're going to take the title, and description, and turn those into the
02:39application's title, and subtitle, and then I'll take each item element, and turn
02:44its data into the artist.
02:46All of that data taken together will show up as an instance of the ArtistData
02:51class, and will be exposed as a public property of the data source simply called
02:56data, once again, with a getter, and a setter.
03:00Now let's talk through how the data is requested, and then processed.
03:03There is a variable called BaseURIString, and it points to the root URI of my RSS feed.
03:11Then, within the GetFeedAsync method, which is marked as asynchronous with the
03:15Async keyword, I'm declaring a feedURIString that appends the name of the
03:21file I'm retrieving,
03:22artists.xml, and then wraps that inside the URI object.
03:28Then the private version of the data object is instantiated; it starts off empty.
03:35Now, within a Try-Catch block, I'm creating an instance of a class
03:38called SyndicationClient.
03:41SyndicationClient is included with the WinRT SDK, and it knows how to download
03:47and parse RSS and atom based XML feeds.
03:51I instantiate the client, and then I call its RetrieveFeedAsync method, passing in
03:57the URI object that knows where the RSS feed is, and this is where the
04:02asynchronous request happens.
04:05The keyword Await means make the request, and wait for the response, and when the
04:11response comes back, expose it as this variable: feed.
04:15The syndication feed class has properties of title and subtitle.
04:20Their values are filled in automatically by the SyndicationClient from these
04:25elements: title, and description.
04:28Then we're looping through a list of objects called items.
04:32That's a member of SyndicationFeed, and each item in that collection will show up
04:37as an instance of SyndicationItem.
04:39Just as with the SyndicationFeed, the SyndicationItem translates the elements from the RSS feed.
04:46The title becomes the title, the description becomes the summary, and then any
04:52links show up as an ordered collection, where you can retrieve the items one at a time.
04:57In my RSS feed, each item only has one link, and so it will be referenced as Item(0).
05:03So, for each item that's retrieved, I create an instance of the ArtistItem class,
05:08I fill in its ArtistName, and Biography from the title, and summary, and then I set
05:13the ArtistPhoto, and ArtworkPhotos by using the link from the RSS feed, and
05:19attaching to that names of folders that are on the public Web site, that contain
05:24the actual graphics I'll be using.
05:26Finally, at the end of the loop, I add the artist object to the list of items.
05:31When the loop is done, the data is ready to use by the rest of the application.
05:36So, now I'm going to add a very small amount of code.
05:39This code will be executed as the application starts up, and it'll go into this
05:44file: MainPage.xaml.vb; the code-behind file for my main page.
05:50I'll open the file, and then place the cursor after the existing sub I'm
05:54navigated to, and I'll create another subroutine.
05:59I'll start this off with private, and then async.
06:03I'm going to be doing asynchronous operations in this method, so I have to mark it this way.
06:08Then I'll use the keyword sub, and I'll give this method a name of RetrieveData.
06:15When I press Enter, the required keywords End Sub are added for me.
06:20Within the subroutine, I'll create a new variable called DataSource, and I'll set
06:25it's data type as ArtistDataSource, and that's one of the classes that I included
06:30in this version of the project, and I will instantiate that with the class'
06:35automatic constructor method.
06:38Now I'm ready to do the asynchronous request.
06:41I'll start with Await, then DataSource.GetFeedAsync.
06:48At this point, the request goes off to the remote Web site, and this thread is
06:53released until the data comes back.
06:55When the data is returned as the feed response, I can then get to the data
07:00through the data source object.
07:02For the moment, I'm just going to do a little bit of debug output.
07:06I'll use Debug.WriteLine, and I'll first output the title, which I'll get from
07:11DataSource.Data.Title.
07:14Then I'll copy and paste that code, and for the second one, I'll output subtitle.
07:21Those are the two string-based properties of the ArtistDataSource class' data object.
07:27Next I'll loop through the list of items using this code.
07:31For Each artist As ArtistItem -- I'm declaring a local variable named artist; data
07:36type is ArtistItem -- In DataSource.Data.Items.
07:41So now any code within the For Each loop will be executed once for each artist I
07:46retrieved, and I'll keep it simple;
07:48I'll once again use Debug.WriteLine, and I'll output artist.ArtistName,
07:55and that's all I need.
07:57The only two critical functional lines of code are right here.
08:01Everything else is debug output.
08:03Finally, to execute this code, I'll go to the OnNavigatedTo method.
08:08This method will be executed automatically as the page comes to the screen, and
08:13I'll call the new method RetrieveData.
08:16I'll save those changes, and now I'm ready to test.
08:19I'll run the application in debug mode by pressing F5.
08:25When the page comes to the screen, I'll return to Visual Studio, and then I'll
08:29look at the Output panel.
08:31If it's not visible, press Alt+2 to bring it to the screen, and you'll see that
08:35the data has been successfully retrieved.
08:38I'm outputting the title and subtitle here, and then the list of artist names.
08:43So if you've gotten that far, then you know you're successfully retrieving data
08:47asynchronously from the RSS feed on the public Web site, and you're ready to go on
08:52to the next step: displaying this data in a list.
Collapse this transcript
Displaying a list of data with XAML and bindings
00:00In previous videos, I created a two column display, and then added code to
00:05retrieve data at run time from a Web site.
00:08I'm working in a version of the project, DisplayList, that has all of that code in place.
00:13The code to retrieve the data is in the code-behind the file; MainPage.xaml.vb.
00:19I'm going to start in this file. The only two lines of code in the RetrieveData
00:23Sub routine that are doing useful work are the one that create the DataSource
00:28object, and then call the GetFeedAsync method.
00:31I'm going to comment out all the rest of the code. That's just debug output.
00:36I'll select those lines of code, then go to the menu, and chose
00:39Edit > Advanced > Comment Selection.
00:43The next step is to make the data accessible to the rest of the page, and I'll do
00:48that using a property of the page called the data context.
00:52The data context is how you'll bind data from the data source object to the
00:57visual controls that the user sees.
01:00I'll place the cursor after the call to the GetFeedAsync method, and then I'll
01:04set the data context using this code: Me.DataContext = DataSource.Data.
01:13Remember that the data object is an instance of this class: ArtistData.
01:18It has a title, and a subtitle, and a list of artists.
01:24I'll go back to the code-behind file, and save those changes. Then go back to the
01:28visual file, MainPage.xaml, and look at it in XAML view.
01:33Let's review the code that's already in place.
01:36Within the outer grid, there are two rows;
01:39one with a height of a 180 pixels, and one that takes up the rest of
01:43the available space.
01:44Then there is a stack panel, and it contains two TextBlock controls.
01:49Right now these TextBlock controls are outputting static text; PageHeader, and PageSubheader.
01:55I'm going to replace those values with binding expressions.
01:59Remember that the page has a data context that's already pointing to my data.
02:04So, for a simple value that's a property of that data, all I need to do is refer
02:09to the property by its name using this sort of code.
02:13I'll delete the static text, and then put in a pair of braces, and I'll start with
02:18the keyword Binding, and then I'll type in the name of the property.
02:22You won't get code help.
02:24That is, it won't autocomplete for you,
02:26so you just need to make sure that you're spelling it correctly.
02:30I recommend frequently going back to your data object code, and checking the name
02:34of the public property, and in fact, to make sure you're getting it right, you
02:38can select and copy it, and then you can paste it into the XAML code.
02:43That's what I'll do with the SubTitle.
02:46I'll go to the second TextBlock, and I'll get rid of the static text in the Text property.
02:52Once again, I'll create a Binding expression, and now I'll paste in the name of
02:56the property, SubTitle.
02:58Before I go any further, I'll save, and test that much code.
03:01Remember that these values are coming from the RSS feed,
03:05so if they show up correctly when I run the application, which I'll do without
03:10debugging, then I know that the data is coming through correctly. And there is
03:14the result, Roux Academy 2012 Art Conference and Featured Artists are values
03:19coming from the RSS feed, so I'm in pretty good shape.
03:23I'll go back to Visual Studio, and now I'll work on the artist list.
03:28Scrolling down a little bit further, within the outer grid, there is a nested grid
03:33which is serving as the second row of the outer grid.
03:36This grid is separated into two columns.
03:40The first has a minimum width of 320 pixels.
03:43That's a very specific value, and the reason I'm using that is because when an
03:48application is snapped; that is, when it's laying side by side with another
03:53application, and it's taking up the smaller column, it will always be 320 pixels wide.
03:59So, my first column has a minimum width of 320, and my second pixel is taking up
04:05the remaining space, but I'm using ratio sizing, or star sizing to say that if
04:11there us enough space, the first column should be one third, and the second
04:15column should be two thirds of the space.
04:17Within that grid, I have a ListView, and that's making up the first column, and
04:23that's the code that I'm going to fill out to display the list of artists.
04:27First I'm going to assign this ListView a name.
04:30I'll assign x:Name, and I'll call it ItemListView.
04:34I'm going to need that identifier later on when I bind values from the list to
04:39the detail view on the right.
04:42Next, I'll pass data into the item ListView, once again, using a
04:46Binding expression.
04:48I'll place the cursor at the end of the begin tag, and make a little bit of extra
04:52space, and then I'll set a property called ItemsSource, and I'll use a Binding
04:58expression, and I'll bind it to the Items property of my data object.
05:04Once again, going back to the ArtistData class, I'm using the named property,
05:09which is exposed here as a Public Property.
05:12That's the list of artist objects.
05:14So, now I'll go back to the ListView, and the next step is to define how each row
05:20of the list is going to look.
05:22I'll make some space between the beginning and ending tags, and I'll add a
05:26property called ListView.ItemTemplate.
05:33Initially, put that in as simply a beginning and an ending tag.
05:39I'll close up some of that extra white space, and then, within the ItemTemplate,
05:44I'll create an instance of an object called a DataTemplate.
05:49Once again, that's defined as a pair of tags.
05:52Now, within the DataTemplate, you can add any visual controls you want.
05:57I'm going to use an image, and a textblock, and I'm going to lay them out side by side.
06:03To do that, I'll use a StackPanel, with an Orientation of Horizontal.
06:09Then, within the StackPanel, I'll create an Image.
06:13Initially, I'll just put in the tag with a closing tag syntax, and a TextBlock,
06:19and I'll do the same thing here.
06:21Now I'll come back to the Image.
06:23Remember that the ListView has a Binding to the Items property of the data object.
06:29As a result, each instance of my DataTemplate will have a binding to one item
06:34in the Items object, and I can bind to the individual properties of that item,
06:39such as the ArtistPhoto, and the ArtistName, and that's what I'll do next.
06:44I'll go to the Image tag, and I'll set its Source attribute.
06:49I'll use a Binding expression, and I'll bind to ArtistPhoto.
06:52Let's take a look at the ArtistItem.vb file.
06:56ArtistPhoto is a public property of that file; that's what I'm binding to.
07:01And this getter method is what will be called each time the binding is executed.
07:06Going back to MainPage.xaml, I'll set some dimensions, with a Width of 100, and a Height of 100.
07:15I'll open up this window to full screen by pressing Alt+Shift+Enter, so I can
07:19see all of the code,
07:21and then I'll add code to the TextBlock.
07:24Just as with the Image tag, I'll use a Binding, this time to the Text property,
07:28and I'll set it to a Binding of ArtistName.
07:35I'll set an explicit FontSize of 18 pixels, and a Margin of 5,0,0,0.
07:43That will create a 5 pixel horizontal gap between the image and the text block.
07:49So, now let's save, and run the application again.
07:55When the application opens, the request for the remote date is sent out, and when
08:00the data comes back, it's transformed by my code in the DataSource class into
08:05something I can bind to.
08:07The XAML file has the Binding expressions, and this results in displaying the
08:12list of artists that you see here.
08:14Once you have the list, you can scroll up and down, you can click to select
08:19individual artists, and eventually you'll be able to do some more with this data,
08:24including displaying the details of the selected data on the right, and sharing
08:28that data with other applications installed in Windows 8.
Collapse this transcript
Displaying detailed data with bindings
00:00So far, I've described how to retrieve data, and then display that data in a
00:05list using bindings.
00:07Now I'll show you how to use bindings to move data from one visual control to another.
00:12In the current version of my application, in this version of the project,
00:16DisplayDetail, when I run the application, it successfully displays the data in a list.
00:22Now I'd like to set things up so that when the user clicks on one of the items
00:27in the list, the details of the data from that item are shared with visual
00:32controls on the right side to create a detailed display.
00:36So, I'll go back to Visual Studio, and I'll look at MainPage.xaml in XAML view.
00:44I'll scroll down toward the bottom of the code.
00:46Previously, when I created my ListView control, I assigned it a name of
00:52ItemListView, and I'm going to use that identifier to get the data from the
00:57currently selected item in the list, and pass it to the visual controls in the right column.
01:03My right column consists currently of a StackPanel, with a default orientation
01:08of vertical, and two TextBlock controls nested within it.
01:13I'm going to set the StackPanel's data context, to get the data from the ItemListView.
01:19I've already used the DataContext property once at the page level, but you can
01:24assign a data context to any visual control; not just the entire page,
01:30and if you assign it at the visual control level, it'll override the page.
01:35So, I'll place my cursor after the name of the tag, StackPanel, and I'll make
01:39a little bit of extra space, and then I'll set a DataContext attribute using a Binding.
01:45This binding will be a little bit more complex than the ones I've used previously.
01:49For simple bindings, where you're binding, say, to a simple string, you just need
01:54to name the property you want from a data object.
01:57But when you're getting data from another visual control, you need to say
02:01both which control you want, and which property of the control you want to get the data from.
02:07You do this with two values of the binding expression.
02:11The first one is ElementName, and you set that to the name of the object
02:15you want to bind to.
02:17For this one, it will be ItemListView.
02:20Then after a comma,
02:21put in a path, and set the value of the path to the property SelectedItem.
02:28The SelectedItem property of the ListView control is filled in automatically
02:33each time the user clicks on an item.
02:36Whenever it changes, that will trigger this binding to update.
02:40It'll get the data, and pass it to its nested visual controls.
02:46So now, within the visual controls, the two TextBlocks, I can use Binding
02:51expressions to set their Text values.
02:53I'll set the Text property of the first TextBlock using a Binding, and I'll set
03:00it to ArtistName, just like I did with the TextBlock in the item itself.
03:06Then I'll go to the second one, and I'll set a Binding again, and this time I'll
03:11use the property Biography.
03:14Remember again that I'm getting these property names from the ArtistItem class.
03:19The list is showing a list of ArtistItems, and each ArtistItems has the
03:24properties ArtistName, ArtistPhoto, ArtworkPhoto, and Biography.
03:31So, I'll test just that much code and see how I'm doing.
03:37I'll run the application, and when it first appears, it shows the list of artists.
03:42Then I'll click on one of the artists, and I see the data is successfully
03:47transferred from the item in the list to the detail objects on the right,
03:52and each time I click on an item, I'm seeing the data on the right update.
03:57Now, in addition to the two textblocks, I'd also like to show an image of one
04:02of the artist's artworks, and I already have that information in my data class; the ArtistItem.
04:08So, I'll go back to Visual Studio, and I'll open up my code to full screen, so
04:13I can see all of it.
04:15Then I'll add some space under this second TextBlock, and I'll create an Image control.
04:22I'll set its Source attribute to a Binding, and I'll use the property name ArtworkPhoto.
04:30I'll set its Height to 400 pixels, but I'm not going to set its Width. I'm going
04:35to allow that to adjust automatically.
04:38If I set an explicit Height and Width on this Image control, it will result
04:42in skewing at least some of the images, because they aren't all the same dimensions.
04:47Then I'll set a Margin of 20,20,0,0. That will result in placing the image 20
04:56pixels from the left side of the column, and 20 pixels from the bottom of the
05:01previous text block.
05:03I'll save my changes, and run the application again.
05:07I'll click on an item, and I see both the artist's name, and biography, but also an
05:13image of one of their artworks.
05:15And each time I click now, I'm seeing the data from that selected artist.
05:20So that's a look at some of the many ways that you can use bindings to get data
05:25from a data object that's set to the data context of a visual control.
05:30Bindings make it incredibly simple to display data in whatever form you need to
05:35in your Windows 8 store application.
Collapse this transcript
3. Integrating Windows 8 Features
Adding an app bar
00:00One of the defining features of a Windows Store app is the placement of
00:04commands in the app bar.
00:06I'm working in the Pictures app that's included with Windows 8, and I've opened
00:10up a catalog of photos.
00:12I'm going to right-click on one of the photos, and that results in bringing up an
00:17app bar that has commands that apply to that selected photo.
00:21In this application, I can then select other photos, and then, for example, I
00:26might select Slide show, and that would open up a slide show of just the selected photos.
00:32I can right-click again, and that brings up other commands, or right-click to
00:37make the app bar go away.
00:39If I were working on a touch-based device, such as a tablet, I could bring up the
00:44app bar by swiping in from the top or the bottom of the application.
00:49I'm going to describe how to create a very simple app bar in the application
00:53that I've been building.
00:55I'm working in a version of my project named AppBar from Chapter 03 of
00:59the Exercise Files.
01:01In my current application, I'm downloading data from an RSS feed on a public
01:05Web site, displaying it in a list, and allowing the user to select individual
01:11artists to display their details.
01:14Now I'm going to add an app bar to the application that has a single command.
01:20I'll go back to Visual Studio, and look at MainPage.xaml in XAML view.
01:26An app bar can be placed either at the top or at the bottom of the screen, and you
01:30control it as the developer.
01:33I'll scroll down to the bottom of the code, and place the cursor after the Grid,
01:37and I'll create a new property called Page.BottomAppBar.
01:45This is how you control where the app bar appears.
01:47On a touch device, the user can swipe from the top or the bottom, but that has
01:52nothing to do with the position of the app bar.
01:54The only thing that determines it is whether you use tags of BottomAppBar or TopAppBar.
02:00Within the BottomAppBar tags, I'll create an AppBar tag set, and I'll give the
02:05AppBar object a name attribute of MyAppBar.
02:10Now, within the AppBar, I can add as many buttons as I like.
02:15App bar buttons have a very specific appearance, and I'm going to create a button
02:20that has a Refresh icon.
02:23In order to create these icons, you need implement styles, and these styles are
02:29predefined in the StandardStyles.xaml file.
02:32But in a brand new application, the styles are commented out.
02:36This reduces the size of the application by not including graphics that you're not using.
02:41But if you want to include one of these styles, you have to uncomment it.
02:46So, I'll go to StandardStyles.xaml, and I'll press Ctrl+F to search, and I'll
02:51search for RefreshAppBar, and that takes me to the RefreshAppBarButtonStyle.
02:58I'll activate this style by adding comment tokens.
03:02Above the style, I'll close the previous comment, and then after the style,
03:07I'll start a new comment, and now RefreshAppBarButtonStyle is available to my application.
03:15When I use this button, it will show an icon, and the icon is defined by this code.
03:21If you scroll around a bit in the StandardStyles.xaml file you'll find
03:25predefined styles for a lot of common commands.
03:29Here I'm seeing commands for Mail, Search, Help, and Upload, and there are many, many others.
03:36I'll save those changes, and return to MainPage.xaml, and within the AppBar, I'll
03:41create a Button, and then I'll set its Style attribute, and I'll use a
03:46StaticResource expression.
03:49I'll start with a pair of braces then the keyword StaticResource and then the
03:53name of the style RefreshAppBarButtonSyle.
04:00I'll finish up the Button tag, save my changes, and run the application, and when
04:06it comes to the screen, I'll right-click in the empty area over on the right, and
04:11I'll see the app bar appear from the bottom showing the Refresh button.
04:16The button doesn't do anything yet.
04:18In order to make the button do something, I need to add a click event handler,
04:22just like any other button.
04:25So, I'll go back to the code, and I'll select the Button tag name, and then I'll go
04:30over to the Properties panel on the right.
04:32With the button selected, I can affect the properties and event definitions for the control.
04:37I'll click on the event handler icon; that's the little square button with
04:42the lightning bolt.
04:43Then I'll double-click into the text box next to the Click event.
04:48That generates a new click event handler; a subroutine called Button_Click_1,
04:55and all I'm going to do in this code is recall the code that's retrieving the data from the Web.
05:02I'm going to call the method RetrieveData.
05:08I'll save my changes;
05:09I'll run the application again.
05:12When the application opens, it automatically downloads the data from the Web, and
05:17I can select items from the list, but now I'll right-click in the detail area,
05:23and when I click Refresh, the data is re-retrieved, the list refilled with data,
05:28and the details are cleared on the right,
05:31And that's the visual indicator that my refresh has worked.
05:35I encourage you to play with the app bar architecture adding your own buttons, and
05:40looking at examples from the Windows 8 store apps examples and documentation.
05:45There are guidelines in the documentation describing how you should arrange your
05:50buttons; when you have multiple buttons, which buttons should hug the right side,
05:54which buttons should be on the left, and so on.
05:56Buttons in app bars are essentially a replacement for many of the functions that
06:01might have gone into menus in traditional Windows apps.
06:05Learning how to create your own app bars can add enormous functionality to
06:09your Windows Store app.
Collapse this transcript
Using the sharing contract
00:00Many features that you might have exposed through menus in traditional Windows
00:04applications are instead handled through the charms in Window Store apps.
00:10The charms appear when you move the mouse cursor to the top left or top right
00:15corner if you're using a mouse, or when you swipe in from the right on a touch device.
00:20There are five charms:
00:22Search, Share, Start, Devices, and Settings.
00:26In this video, I'm going to describe how to intergrate with the Share charm;
00:31that is, how to share data from an application.
00:34I've opened up the photos app that's included with Windows 8, and I'm going to
00:38right-click on one of the photos, and then move the cursor to the top right
00:43corner, and choose Share.
00:45When I do this, this sends an event to the application, and the application then
00:51tries to share data to whatever other applications can handle it.
00:55In the case of the photos app, it's going to share the actual photo, and Windows
01:008 shows a list of all applications that have registered to say that they can
01:04handle this kind of sharing.
01:06If I click on the Mail application, that generates a new e-mail, and attaches
01:11the selected photo.
01:12So, now I'm going to describe how to use Visual Basic code to do this sort of sharing.
01:18I'm going to keep it simple.
01:19I'm not going to do something complex, like sharing a photo, but I am going to
01:23show you all the code you need to share simple text.
01:27I'm working in a version of the project called SharingContract, and I'll open
01:32the code-behind file for my main page; that's Mainpage.xaml.vb.
01:38The first step is to create a field in your class that's an instance of the
01:43class data transfer manager.
01:46I'll place the cursor after the class declaration, and I'll create a new field,
01:50which I'll declare with Dim, and I'll add the keyword WithEvents.
01:55This tells the compiler that this object will be generating events that I can
02:00listen to, and handle.
02:02I'll name the object transferManager, and I'll set its data type to
02:09DataTransferManager.
02:11Notice that I'm not getting autocomplete help.
02:14That's because this class is a member of an assembly that is not
02:19automatically imported.
02:20To add the required import statement, I'll move the cursor off the class name,
02:25then I'll move the cursor over the little icon that appears, and I see the
02:29message, Type DataTransferManager is not defined.
02:33Then I'll move the cursor around a little bit until I see this red icon with
02:38the X. I'll open the list of available options, and I'll select the first one,
02:43ImportWindows.ApplicationModel.DataTransfer; that's the name of the assembly
02:49that defines this class.
02:51By selecting the item, I've added an import statement to the top of the code,
02:56and now I can use the DataTransferManager class, and any other classes that are
03:01members of that assembly.
03:03Now, I've only defined the object, but I haven't instantiated it yet, and I'm
03:07going to do that work in the OnNavigatedTo method that's called automatically
03:13as the main page comes to the screen.
03:15I'll place the cursor within that method before the call to the RetrieveData method.
03:20Here, I will instantiate the object.
03:23I'll use this code: Me.transferManager = DataTransferManager.GetforCurrentView.
03:33That means, give me the DataTransferManager object that's associated with the current page.
03:40I'll move the cursor off the line, and all the errors go away.
03:44Now, the next step is to create a method that will be called whenever the Windows
03:488 operating system tells the application, I want to share something from you.
03:53I'm going to create the method first, then I'll come back here and register it.
03:58I'll place the cursor after the current sub routine.
04:01I'll scroll down a bit, and then I'll go into full screen mode, because I'm about
04:05to type quite a bit of code.
04:07I'll declare a new Private Sub routine.
04:10I'll name it OnDataRequested, and it's going to received two arguments;
04:15a sender argument, which will be an instance of the DataTransferManager method,
04:22and then an EventArguments object. This EventArguments object will be used to
04:27communicate with the sharing contract, and I'll set it's data type as
04:31DataRequestedEventArgs.
04:35When I press Enter, the End Sub keywords are added.
04:39The event arguments have a property called the DataRequest.
04:43The DataRequest object is how you'll attach data to send back to the sharing contract.
04:50So, I'll create a new variable, which I'll name request, and I'll set its data
04:55type as DataRequest, and I'll get its value from e.Request.
05:02Now, in my application, I want to share data from the currently selected
05:06artist, and I can get information about that artist from the selected item of the list view.
05:12So, I'll create a new variable called artist,
05:15I'll set its data type to ArtistItem, and I'll get its value from ItemListView --
05:21that's the list view that I declared in XAML code -- .SelectedItem.
05:27So, now I have data that I can share.
05:29Now I need a little bit of conditional code.
05:32If the user selected an artist from the list, then my artist object will
05:36have data to share,
05:37but if they didn't, then the artist object will be null, which in Visual Basic we
05:42refer to as nothing.
05:44So, I'll add an If clause, and I'll say, If artist Is Nothing Then, and then
05:52I'll send a message back to the sharing contract that tells it to display an error message.
05:59You'll do this using the request objects method, FailWithDisplayText.
06:04So the code will be request.FailWithDisplayText, and then I'll pass in a static message,
06:11Select an artist to share.
06:15So, I'm not just telling the user they've done something wrong; I'm telling
06:19them how to correct it.
06:20Then I'll add an Else clause, and here is where I can actually share some data.
06:26The request object has a property called Data, and it has an object called Properties.
06:31Within the properties, you can set a title, and a description.
06:35I'll start with the title using this code: request.Data.Properties.Title, and I'll
06:43set that value to the ArtistsName for the currently selected artist.
06:47Then I'll set the description with request.Data.Properties.Description, and I'll
06:55set that value to a static string of Featured Artist.
06:59Finally, I'll call a method called SetText of the data object.
07:04I'll use request.Data.SetText.
07:09Notice that there are a bunch of Set methods.
07:12This is how you can supply a bitmap -- that is, a graphic -- complex data, a data
07:17provider, and a lot of other formats. Again, my goal is to keep this simple,
07:23so I'm going to use SetText, and I'll pass in the artist's biography.
07:29So, that's my completed event handler on data requested.
07:33Now I have to register the event handler method with the data transfer manager,
07:38so that when the event data requested happens, I tell it where to get the data from.
07:44I'll come back to the method OnNavigatedTo, and place the cursor after the
07:49instantiation of the transferManager, and I'll add this bit of code:
07:54I'll use AddHandler, and then I'll pass in the event I'm listening for,
07:59Me.TransferManager.DataRequested. Then I'll put in a comma, and then a reference
08:06to the on data requested method.
08:08It will look like this,: AddressOf Me. OnDataRequested, and that's this method that
08:16I already created defined as a Sub routine.
08:19Now, when the request from the sharing contract comes in, it will be routed to
08:24this method, and this method will pass the data back.
08:27So, that's all the code I need to share data with the sharing contract when it's requested.
08:33There is one other very important step, though, and that's to de-register the
08:37event handler when the user moves away from this page.
08:40That's so you don't end up creating a whole stack of identical event handlers.
08:45You do this in a method called OnNavigatedFrom.
08:49It looks very similar to OnNavigatedTo, so I'm going to select just the method
08:53signature for OnNavigatedTo, and I'll copy that, and I'll paste it down here, and
09:00I'll press enter there to add the End Sub, and I'm going to change the name of
09:04this method from OnNavigatedTo to OnNavigatedFrom.
09:09Then I'll come up here, and I'll select the line that's adding the handler. I'll copy that.
09:15I'll paste it here, and then I'll change AddHandler to RemoveHandler.
09:25So, now the logic is that when the user opens the page, I'm registering the event
09:30handler method, and when they move away from the page, I'm de-registering it.
09:35Now I'm ready to test the application.
09:37I'll save, and run the application without debugging.
09:43Without an artist selected, I'll go to the charms, and I'll select Share, and I
09:48see my error message, Select an artist to share, and that's because there was no
09:54artist selected; therefore, the artist was nothing.
09:57So I'll go back to the application, and I'll choose the first artist.
10:02I'll go back to the sharing contract, and now I see some of the selected data;
10:08the title, and the description, and I see a listing of applications that have
10:12registered to receive this kind of data: text.
10:16In my new installation of Windows 8, the only application that qualifies is Mail.
10:22I'll select the Mail application, and that generates a new e-mail message, and it
10:26shows the data that I passed in: the artist's name, and the biography.
10:31This application allows me to click in here, and type a custom message, or I could
10:35just fill in the recipient, and send it off.
10:39So, those were the critical pieces to building a Window Store app that knows how
10:43to share data with the rest of the apps in the operating system using the Share
10:47charm, and the share contract.
10:50I encourage you to explore a lot of other features of the share contract,
10:54including how to share different kinds of data, and also how to register your own
10:59application to receive data from other apps.
Collapse this transcript
Customizing splash screen and start screen icons
00:00Windows Store apps are represented on the Start screen by tiles, and the tile's
00:05image can be controlled either with static images, or with what are known as live tiles.
00:11I've set my Start screen to only show the static images that are included
00:14with the applications.
00:16In some applications, you can set them to live tiles.
00:20For example, if I go to the Photos app, and right-click, and then Turn live
00:24tile on, I'll see images that are being selected by the application, and sent
00:29to the Start screen.
00:31But before getting into the mechanics of live tiles, you should first create
00:36your own static graphics.
00:39When you create a brand new Windows Store app, it's populated with very
00:43boring static graphics that display this box with an X. It's up to you to
00:49create graphics to brand your application, so it can be represented fairly
00:54on the Start screen.
00:55I'll go to Windows Explorer, and show you where these graphics are stored, and how
01:00they're registered with the application.
01:02Each new project that you create in Visual Studio will have an Assets folder, and
01:07it'll contain these four PNG files:
01:10Logo, SmallLogo, SplashScreen, and StoreLogo.
01:16All of these graphics are pretty much the same.
01:19They all have that square with the X, but they're different dimensions.
01:23These files are registered in the application manifest, which you can find at the
01:27bottom of the list named Package.appxmanifest.
01:29I'll double-click to open it, and then scroll down a ways to the Logo section.
01:37The tile images and logos are listed here.
01:40Their names are Logo, Wide Logo, Small Logo, and Store Logo.
01:46There's also the Splash Screen logo.
01:48In a basic application, you'll have four of these files; simple files for all
01:54but the Wide Logo, and the Splash Screen.
01:56For example, if I go to the Logo setting, and then look at the path, it's
02:02pointing to Logo.png.
02:04Small is pointing to Small Logo, Store to Store Logo, and Splash Screen
02:09to SplashScreen.png.
02:12Because there is no Wide Logo, you're application will not be able to be
02:16represented by a Wide Logo on the Start screen,
02:18but if you want to create one, you can easily, and the required dimensions
02:23are right down here.
02:24Now, to give my application a nicer look and feel, I've already created some
02:29logos, and they match the dimensions of the files that are already included
02:33in the application.
02:35So, I'll go to my Exercise Files, and from there, to the Assets folder, and then to
02:40LogoGraphics, and I'll find five files.
02:44The names of these files match the names that are included in my
02:47default application.
02:49There's also a source PNG.
02:52This file can be opened in Illustrator, or Fireworks, or any other graphics
02:57application that supports layered PNG files.
03:00I'm not going to use that in the actual application. That's just a model that
03:04you can use to build your own logos.
03:07But I'll select these four files, and I'll copy them to the clipboard, then
03:13I'll go back to my Exercise Files, and I'll go to the folder for the current project, AppIcons.
03:20I'll drill down to the project folder, then to the Assets Folder, and here are
03:25the logo files I'm currently using, and then I'll paste, and replace the files.
03:31After the files are put in place, I'll return to Visual Studio, and I'll see the
03:37new files reflected automatically.
03:39I'll run the application without making any code changes, and as the application
03:45comes to the screen, I see my new Splash Screen icon, and when I return to the
03:50Start screen, I see the icon shown in the application tile.
03:55So, that's how easy it is to create your own custom graphics, and add them to your app.
04:01Now, in the next video, I will show you how to make these tiles even more
04:04interesting by implementing live tiles, and doing something similar to what you
04:09see in the Photos app; displaying graphics that are shared by the application
04:14at run time.
Collapse this transcript
Creating Live Tile notifications
00:00The Start screen in Windows 8 can be a very lively environment, because
00:04each Window Store app is capable of sharing information through the live tile architecture.
00:11For example, the Photos app, when you turn live tile on, displays a scrolling
00:16screen, showing one photo at a time,
00:19and the Weather app shows the current weather in your current location.
00:23You can add your own code to display live tiles from your application, and I'll
00:28show you one example of that here.
00:31The first step is to learn about the various tile templates.
00:34Each template is XML based, and you can find them on this page, which is named
00:40Hh761491.aspx in the MSDN library.
00:46There are three types of square templates: text-only, image-only, and what are
00:51known as square peek templates, and then there are also wide templates.
00:56Each template is an XML packet that has a root element of tile, a child element
01:02of visual, and then a set of elements which could be text or images.
01:07I'm going to describe how to use one of the simplest templates.
01:10This is known as the TileSquareImage template. The name of it is here, and the
01:16XML template looks like this.
01:18Within the binding, there's an image tag.
01:21The image tag has an src attribute, and an alt attribute,
01:25and by setting these values, I can affect what my live tile looks like.
01:30I'll go to Visual Studio, where I'm working with the version of my project called LiveTiles.
01:37When I run the application currently, its tile shows up as the static graphic
01:41that I included from the app icons video.
01:45I'm going to drag the tile for this application way over to the left,
01:49so I can easily see it each time I come back to the Start screen.
01:53Then I'm going to turn of some of these other live tiles to eliminate
01:57distractions, and I'll only be looking at my applications tile.
02:02Then I'll go back to Visual Studio, and I'll go to my main page file's code-behind
02:07file, MainPage.xaml.vb, and I'll look at it in full screen mode.
02:14I would like to trigger a live tile each time the user selects an artist from
02:19the list, and so I'm going to add code to an event handler for the list control.
02:25I'll go to the MainPage.xaml file.
02:28I'll scroll, and locate the list view control, and I'll add a new attribute
02:36called SelectionChanged.
02:39Then I'll double-click on the icon that appears that let's me create a new event handler.
02:44That added the name of the event handler method,
02:48ItemListView_SelectionChanged_1.
02:50I'll select it, right-click, and choose Navigate to Event Handler, and that takes
02:56me to the newly generated method.
02:59This is where I'm going to add code to grab the current data, and display it as a live tile.
03:06This event will be triggered when the user clicks on an item from the list,
03:10so I'll know for sure that there is a valid artist item available, and I'll get a
03:15reference to it by creating a new variable that I'll name artist, and I'll set
03:20its data type to ArtistItem, and I'll get its value from the list control, that's
03:25ItemListView, and its SelectedItem property.
03:29Now I need to create a reference to the XML template.
03:34You can do this by putting in raw XML code, or you can use document object model
03:40style programming, and I'm going to the latter. The code is cleaner, easier to
03:45read, and easier to maintain.
03:47So, I'm going to create a new variable that I will call tileXmlDoc, and I'll set
03:52its data type as something called XmlDocument.
03:55This is a class that's not already imported into my class, so I'll move the
04:00cursor off the class name, then go to the error, click on the list of available
04:06fixes, and choose to import the assembly that includes that class, XmlDocument.
04:11The import statement gets added to the top of the class right here.
04:19I'll go back down to the method I'm working on, and then I'll get the value of
04:24the XML doc using the following code:
04:27I'll set its value by starting with an Equals operator, then I'll call a
04:31class called TileUpdateManager.
04:34Once again, this is a class that I need to import.
04:39After it's been imported, I'll move the cursor after the class name again, and
04:42type in a dot, and I'll call a method called getTemplateContent.
04:48Next, I'll use a class called TileTemplateType that includes properties for
04:53each of the available XML templates, and I'll use the template that matches the name
05:01of the template I saw on the documentation, TileSquareImage.
05:06So, now I have an XML template that I can fill in.
05:10Let's look at the template again.
05:11There is an image element that has attributes of src, or source, and alt, and I'm
05:19going to fill in those two attributes.
05:21So, my next step is to get a reference to that image element, and I'm going to
05:26use methods that are a part of the document object model, or DOM style of programming.
05:33I'll create a new variable that I will call imageElements, and I'll set it to
05:38a data type of XmlNodeList, and I'll get its value by calling tileXmlDoc, and
05:44I'll call a method called GetElementsByTagName, and I'll pass in the value of the image.
05:52That's the name of the element that I want to grab.
05:55GetElementsByTagName returns a list of all elements that have that tag name.
06:01I know, because I looked at the template, that there's only one, but I need to get
06:05a reference to that specific element.
06:07So, I'll create a new variable that I'll call imageElement, and I'll set its data
06:12type to XmlElement, and I'll get its value from imageElements, and then I'll pass
06:18in the Item method, and the index of the object, which is 0.
06:23So, I ask for all elements of the same name, and then I got a reference to the one
06:28and only element that should be returned.
06:31Now I'm ready to pass data in.
06:35I'm going to call a method of the Element tag called SetAttribute.
06:40SetAttribute takes two string values: the first is the name of the attribute, and
06:45again, I'm getting that from this listing, src, and then I'm going to pass in
06:50the URL of the artwork photo that's currently selected with the code
06:55artist.ArtworkPhoto.
06:59Next, I'll set the alt attribute to the artist's name.
07:04Once again, I'll call SetAttribute.
07:07I'll pass in the alt attribute name; an artist.ArtistName.
07:14So, now I have an XML packet that contains my data.
07:19I have one more important step.
07:21I'm going to create two objects: a tile notification that's a wrapper around the
07:26XML document, and then a tile updater that knows how to update the live tile.
07:31I'll create a variable that I'll call notification, and I'll set its data type
07:35to TileNotification, and I'll instantiate it using the TileNotification
07:41constructor method.
07:42I'll put in the keyword New, then the name of the class, and I'll pass in my XML
07:47document that contains my tile template that's been filled in with data.
07:52Next, I'll create the tile updater.
07:55I'll create a variable called updater.
07:58I'll set its data type to TileUpdater, and I will instantiate it by calling a
08:04method of TileUpdateManager named CreateTileUpdaterForApplication.
08:11This is a Sub routine, so you don't need to pass in any arguments, but if you
08:16like, you can add the parentheses at the end.
08:19Finally, update the tile; call updater.Update, and pass in the notification, and that's it.
08:27Now, whenever the user selects an item from the list, this method will be called.
08:33We'll get a reference to the selected data.
08:35We'll get the XML template for how we want our live tile to look.
08:39We'll fill in the data, create the notification, create the updater, and
08:44call the update method.
08:46Here is the result.
08:48I'll run the application, and come back to the Start screen.
08:52Because I haven't selected an artist yet, I see the static graphic.
08:58I'll go back to the application.
08:59I'll click on one of the artists.
09:02I'll come back to the Start screen,
09:05move the cursor off the tile, then back over it, and after a moment, the graphic is
09:09updated with the live tile.
09:11Notice that in this template, the original graphic is still used.
09:16It's laid over the live tile content that we specified.
09:20I'll go back to the application again, and I'll choose another artist. I'll come
09:25back to the Start screen, and this time I don't have to move the cursor over the
09:29tile. I just wait a few moments, and the image updates.
09:33So, that's a bit of code that you can use to create your own live tiles.
09:38Again, refer back to the documentation, the live tile catalog, for various types
09:44of templates that you can use.
09:46If your application only includes a square graphic as its logo, and not a wide
09:50graphic, then you can only use square graphics for your live tiles.
09:55If you want to use live tiles that are wide, you'll need to also provide a
09:59static wide logo file.
10:01But this is a great way to brand your application, and let it participate in the
10:05liveliness of the Windows 8 Start screen.
Collapse this transcript
Conclusion
Where to go from here
00:00Thanks for watching this course, Building Your First Windows Store App with
00:04XAML and Visual Basic.
00:06If you're just getting started with XAML, you can buff up your skills with the
00:10lynda.com course Silverlight 5 Essential Training, or you can watch a variety of
00:15lynda.com courses about the features of Visual Studio. You can learn more about
00:20how to program most features of Windows Store apps from the documentation and
00:24sample apps that Microsoft provides.
00:27Start your exploration of these resources at dev.windows.com.
00:32I hope this course helps you get started on your road to creating and
00:36distributing these new kinds of apps for the Windows Store.
Collapse this transcript


Suggested courses to watch next:


Are you sure you want to delete this bookmark?

cancel

Bookmark this Tutorial

Name

Description

{0} characters left

Tags

Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading
cancel

bookmark this course

{0} characters left Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading

Error:

go to playlists »

Create new playlist

name:
description:
save cancel

You must be a lynda.com member to watch this video.

Every course in the lynda.com library contains free videos that let you assess the quality of our tutorials before you subscribe—just click on the blue links to watch them. Become a member to access all 104,069 instructional videos.

get started learn more

If you are already an active lynda.com member, please log in to access the lynda.com library.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Access to lynda.com videos

Your organization has a limited access membership to the lynda.com library that allows access to only a specific, limited selection of courses.

You don't have access to this video.

You're logged in as an account administrator, but your membership is not active.

Contact a Training Solutions Advisor at 1 (888) 335-9632.

How to access this video.

If this course is one of your five classes, then your class currently isn't in session.

If you want to watch this video and it is not part of your class, upgrade your membership for unlimited access to the full library of 2,024 courses anytime, anywhere.

learn more upgrade

You can always watch the free content included in every course.

Questions? Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com.

You don't have access to this video.

You're logged in as an account administrator, but your membership is no longer active. You can still access reports and account information.

To reactivate your account, contact a Training Solutions Advisor at 1 1 (888) 335-9632.

Need help accessing this video?

You can't access this video from your master administrator account.

Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com for help accessing this video.

preview image of new course page

Try our new course pages

Explore our redesigned course pages, and tell us about your experience.

If you want to switch back to the old view, change your site preferences from the my account menu.

Try the new pages No, thanks

site feedback

Thanks for signing up.

We’ll send you a confirmation email shortly.


By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked