03.01.2015 Views

C# 5.0 Programmer's Reference

Visual Studio 2013 C# 5.0 Programmer's Reference

Visual Studio 2013 C# 5.0 Programmer's Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Summary ❘ 23<br />

}<br />

// Place the frame in the current Window<br />

Window.Current.Content = rootFrame;<br />

}<br />

if (rootFrame.Content == null)<br />

{<br />

// When the navigation stack isn't restored navigate to the first page,<br />

// configuring the new page by passing required information as a<br />

// navigation parameter<br />

if (!rootFrame.Navigate(typeof(MainPage), args.Arguments))<br />

{<br />

throw new Exception("Failed to create initial page");<br />

}<br />

}<br />

// Ensure the current window is active<br />

Window.Current.Activate();<br />

If the application’s Frame is null, the code creates a new Frame.<br />

Then if the Frame’s content was null, the bold line of code uses the Frame’s Navigate method to<br />

navigate to a new instance of the MainPage class. (If the Frame’s content is not null, it is a previously<br />

created instance of the MainPage class and it is reused.)<br />

Finally, the code activates the current window, and at that point the MainPage appears.<br />

Summary<br />

Unless you plan to edit <strong>C#</strong> files in a text editor and then use the command-line interface to compile<br />

them, you will end up using Visual Studio to write and build <strong>C#</strong> programs. Because of that, the book<br />

does cover Visual Studio to some extent.<br />

The book’s goal, however, is to cover the <strong>C#</strong> language. This chapter explains the most common<br />

kinds of applications that you can build in <strong>C#</strong>. It shows how you can build programs that provide<br />

buttons or other methods for executing your <strong>C#</strong> code.<br />

Visual Studio enables you to build many different kinds of applications. This chapter explains how<br />

to start with four of those types: console, Windows Forms, WPF, and Windows Store applications.<br />

The remainder of this book assumes you can create one of those kinds of applications so that you<br />

can run <strong>C#</strong> code.<br />

Although this book doesn’t explain user interface programming or Windows Forms, WPF, and<br />

Windows Store applications in more detail, you should look into them when you have a chance.<br />

<strong>C#</strong> code alone enables you to produce some amazing results, but you need a great user interface<br />

to actually show them off.<br />

When you create a new program, Visual Studio creates all sorts of files to represent forms, windows,<br />

code, resources, and other data associated with the project. Chapter 3, “Program and<br />

Code File Structure,” describes the most common kinds of files associated with <strong>C#</strong> projects.<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!