Windows 8 and HTML–Part 1: Simple Example

7/25/2012 12:54:05 PM

This is the beginning of a multi-part series that will explore building a Metro-style HTML/JavaScript app on Windows 8.  I’ll try and keep the videos short, usually around five minutes, though some may go up to around ten.  I will also have a blog post that accompanies each video that will essentially cover the same concepts.  The videos may show some extra tips or tricks, but the basics will be covered here.  Make sure you go to http://aka.ms/30Days to get all the info and resources you need to start building your Windows 8 apps.  Register now and follow my series to hit the ground running on getting your application done and into the Windows Store.

Watch Part 1 Video

Getting Started

I’m assuming you have already installed Windows 8 RP and Visual Studio Express 2012 for Windows 8.  If not, I will wait here for you to get those installed… <insert elevator music here>

Capture1Ok, let’s get started.  First, start Visual Studio and select File->New Project.  Make sure you select a JavaScript from the Templates pane on the left side of the New Project window.  The templates for the different languages look a lot alike.

We will be working with the Navigation App Template.  The Navigation App Template creates a “single page style” HTML app – all content is displayed inside a single HTML page.  The other template (except the Blank App) implement standard navigation hierarchies and provide a sample approach for working with different data. 

Select that and set the name of the application to TweetScan.

Getting Back to First Principles

By default, the project we are working with creates a default.html page that uses WinJS.  We will come back and visit WinJS and how it is used in later installments.  For now, let’s look at how Metro-style apps using HTML and JavaScript are fundamentally HTML and JavaScript, not some “special sauce” implementation of these technologies.

Right-click on the project in the Solution Explorer and select Add->New Item.  Select HTML Page from the Add New Item dialog. You can leave the name as page.html.

Take a look at page.html.  It is nothing but simple HTML, and right now, it has no content.  Let’s add some simple content to the page that will set things up for further exploration.  Add to the <body> of page.html the following markup:

<h1 class="page-title">Demo Page</h1>
<button id="demoButton">Click Me</button>
<div id="target"></div>

Capture2The next step is to configure the application to use our new page instead of loading default.html.  Double-click on the package.appxmanifest file in the Solution Explorer.  Using the Start Page dropdown, change the start page to page.html.  The important thing to realize here is that we are configuring our Metro app to load page.html and that is all since our HTML page does not load any JavaScript, style sheets, etc.  There is no “magic sauce” being loaded – it is for all intents and purposes, just a web page.

Press F5 to run the application.  The easiest way to get back to Visual Studio, IMHO, is to hit Windows Key-D.  This will take you back to the desktop and you can end the debugging session.

Adding Script

Let’s add some functionality to our page.  Right-click on the project in Solution Explorer and select Add->New Item.  Select JavaScript file from the Add New Item dialog.  You can leave the name as script.js.  Add the following Javascipt to the new script file

(function () {
 
    window.onload = function () {
        var button = document.getElementById('demoButton');
        button.addEventListener('click', doSomething);
    };
 
    function doSomething()
    {
        target.textContent = "Bang!";
    }
})();

Switch back to page.html and drag the script.js file from the Solution Explorer to inside the <head> tag of page.html. This will add a reference to script.js so it is loaded when page.html is loaded.  Press F5 to run the application and click the button.  “Bang!” should appear in our target <div>.  Go back to Visual Studio and stop debugging.

Add Style

So far, everything is working just like it would work in a web page inside a browser.  The same holds true for styling with CSS.  Add a new style sheet to your project in the same manner you added files earlier.  Add the following CSS to the new file

body {
    font-family: 'Segoe UI';
}

.page-title {
    font-size: 48px;
}

#target {
    font-size: 36px;
    font-style: italic;
}

Add a reference in page.html to the new style sheet just like you did for the JavaScript file (drag and drop to the <head> element).  You can now press F5 and see how the styled page looks.

Bonus Step

If you want to get a glimpse at some of the things that are built in to Metro style apps, you can navigate to the following in Solution Explorer: References->Windows Library for JavaScript 1.0.RC->css.  You can drag one of the two css files to page.html and run the application again.  You will see the default Metro style applied to your application.

Tags:

Windows 8

Windows 8 Hackathon–Eternal Glory Can Be Yours (and cool prizes!)

7/18/2012 3:00:01 PM

667px-Triwizard_cupOn Friday, August 24th, starting at 9:00 AM at the Microsoft Edina office, we will be hosting a Windows 8 Hackathon.  You, worthy challenger, will be asked to develop a Windows 8 Metro-style application using either XAML, C++, C#, or HTML/JS and competing against other devs for eternal glory.  Oh, if your app is picked as one of the top three apps of the Hackathon, you will also win a Samsung Series 7 Slate AND a $500 gift card.  That’s right, three developers will win ~$1,800 in hardware and “cash”.  Come up with a truly great idea, and maybe become part of Generation App.  But I’m sure the eternal glory is much more important to you. :)

How do you win?  A panel of esteemed judges, including yours truly, will be evaluating your application in four areas:

  1. Concept:  The more creative the application, the higher you can score.  Face it, another Calculator app is nice, but MegaTweetFace with Extra Hot Sauce is a much cooler application. No, I have no idea what MegaTweetFace with Extra Hot Sauce would actually be, but you get the idea.
  2. Design:  How well does your application leverage Metro UX design principles?  Metro UX is more than boxes and monochrome colors, so if you don’t know how to design a cool Metro UX, make sure you ask a mentor at the event, check out http://design.windows.com, or come to the Windows 8 Dev Camp the day before (see below for details).
  3. Metro Principles:  Does your app leverage things like Search, Share, Settings or other Windows 8 “Win as One” capabilities?  The more you use Metro features like that, the more points you will score.
  4. Functionality:  How much works, what features are implemented, etc.?  Pretty easy to understand, though don’t show anything that crashes your app our you may be subjected to public humiliation, peer ridicule, and the title of Crash McGee. Ok, not really, but it sounded like fun.

You can register for the Hackathon here – http://aka.ms/MSPHack.  Don’t delay, space is limited!!!

Want to learn about Windows 8 dev using either XAML, C++, C#, or HTML/JS, you may want to come to the Windows 8 Dev Camp the day before – http://aka.ms/Camp  You can also check out Windows 8 in 30 Days.

We’ll be holding more Dev Camps and Hackathons in the near future, so if you can’t get into the August event, stay tuned for upcoming announcements.

Update:  Hackathon FAQ

  1. Will I be able to get technical assistance? Yes.  There will be several different mentor/judges available while you are coding.  Use them.  Learn from them.  They can’t help you write your app, but they can answer questions, help with bugs, etc.
  2. Do I have to finish the app at the Hackathon?  No.  Get done what you can get done.  The more you get done, the better your score, but you are not disqualified by not having a completed app.  Frankly, if you can get your app done in less than 12 hours, I think you will be scoring poorly on other areas outside of functionality.
  3. Can I use OSS?  Yes.
  4. Can I  start coding my app before the Hackathon?  Bringing with you things like design assets, flow diagrams, etc. is fine, but you shouldn’t have much done re: coding your app beyond File-?New Project.  It’s the honor system.
  5. How can I learn Metro Design?  The http://design.windows.com web site is a good place to start.  Also checkout http://buildwindows.com for videos related to design.  If there is enough interest, we can deliver a “Intro to Metro Design” presentation at the beginning of the Hackathon.

Tags:

Headlines | Windows 8

Heartland Dev Con Lab Session

7/12/2012 10:41:23 AM

I’m very excited to announce that I will be teaming up with Matt Milner(@milnertweet) to present a Hands-On Lab session covering HMTL/javascript apps on Windows 8 at the Heartland Developer Conference.  You can get all the session details and register for the session here.

Tags:

Headlines | Windows 8

Powered by BlogEngine.NET 1.6.0.0
Theme by Mads Kristensen

About the author

Jeff Brand Jeff Brand

This is the personal web site of Jeff Brand, self-proclaimed .NET Sex Symbol and All-Around Good guy. Content from my presentations, blog, and links to other useful .NET information can all be found here.

E-mail me Send mail


Calendar

<<  May 2013  >>
MoTuWeThFrSaSu
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

View posts in large calendar

My Twitter Updates

XBOX
Live

Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2013

Sign in