Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli [email protected] Intel...

26
Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli www.Intel-Software-Academic-Program.com [email protected] Intel Software 2013-03-20

Transcript of Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli [email protected] Intel...

Page 1: Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli  paul.guermonprez@intel.com Intel Software 2013-03-20.

Win8 on Intel Programming CourseDesktop : WPF

Cédric Andreolliwww.Intel-Software-Academic-Program.com

[email protected] Software

2013-03-20

Page 2: Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli  paul.guermonprez@intel.com Intel Software 2013-03-20.

What is WPF?

Page 3: Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli  paul.guermonprez@intel.com Intel Software 2013-03-20.

What is WPF?WPF: Windows Presentation FoundationRenders graphical elements (through DirectX)Can be programmed with Visual Studio

The viewWritten in XAML (Extensible Application Markup Language)Visual Studio provides a wysiwyg tool

The application coreWritten in C#

Page 4: Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli  paul.guermonprez@intel.com Intel Software 2013-03-20.

What is WPF?Native librariesC# allows to use native librariesYou sometimes need to write a wrapper

C# can access most of the WinRT libraryWinRT offers a simple APIGives access to devices such as:

SensorsGPSetc.

C#

Wrapper

C++ library

Page 5: Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli  paul.guermonprez@intel.com Intel Software 2013-03-20.

Getting started with WPF?

Page 6: Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli  paul.guermonprez@intel.com Intel Software 2013-03-20.

Getting started with WPF?Step 1: Create a WPF projectIn Visual Studio, create a new project (with a new solution)File -> New -> Project -> WPF Application

Page 7: Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli  paul.guermonprez@intel.com Intel Software 2013-03-20.

Getting started with WPF?Step 2: Run your projectClick on the play button

Page 8: Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli  paul.guermonprez@intel.com Intel Software 2013-03-20.

Getting started with WPF?Step 3: Open the XAML fileThe file « MainWindow.xaml » is a XML file that represents the viewDouble click on it. The wysiwyg editor should open

Page 9: Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli  paul.guermonprez@intel.com Intel Software 2013-03-20.

Getting started with WPF?Step 4: Display the ToolboxThe toolbox allows to add new controls in your view but…You must configure Visual Studio to display it!

Page 10: Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli  paul.guermonprez@intel.com Intel Software 2013-03-20.

Getting started with WPF?Step 4: Display the ToolboxYou can change the Toolbox parent panel by Drag and Drop

Page 11: Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli  paul.guermonprez@intel.com Intel Software 2013-03-20.

Getting started with WPF?Step 5: Add a labelJust drag and drop a Label from the Toolbox to the view

Page 12: Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli  paul.guermonprez@intel.com Intel Software 2013-03-20.

Getting started with WPF?Step 6: Change the styleIn the main view, select the label and open the Properties panel

Page 13: Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli  paul.guermonprez@intel.com Intel Software 2013-03-20.

Getting started with WPF?Step 6: Change the styleIf you can’t find the Properties panel, you will have to add it!

Page 14: Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli  paul.guermonprez@intel.com Intel Software 2013-03-20.

Getting started with WPF?Step 6: Change the styleIn the Properties panel, set the font size to 34px

Being able to modify the UI style through the Visual Studio interface avoid loosing a lot of time.

Page 15: Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli  paul.guermonprez@intel.com Intel Software 2013-03-20.

Getting started with WPF?Step 7: Add other UI elementsAdd the following elements:

An other Label

A TextboxA ButtonAn empty Label

Page 16: Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli  paul.guermonprez@intel.com Intel Software 2013-03-20.

Getting started with WPF?Step 8: Add Name propertiesA name allows to identify a field and to retrieve it in your programTo retrieve the content of the Texbox, add a name propertie to your Texbox (Select the Textbox and click on the properties panel)

Page 17: Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli  paul.guermonprez@intel.com Intel Software 2013-03-20.

Getting started with WPF?Step 8: Add Name propertiesAdd a name property to the output Label

Page 18: Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli  paul.guermonprez@intel.com Intel Software 2013-03-20.

Getting started with WPF?Step 9: Add a handlerA handler intercepts the actions that come from the userSet the name property for the button (use « Click » for example)

Create the handler with Visual StudioIn the design view, double click on the buttonVisual Studio will create the handler for youThe name of the handler will be send_Click (if you

named you button « Click »)

Page 19: Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli  paul.guermonprez@intel.com Intel Software 2013-03-20.

Getting started with WPF?Step 9: Add a handlerYou should be automatically redirected to the C# file editor

Page 20: Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli  paul.guermonprez@intel.com Intel Software 2013-03-20.

Getting started with WPF?Step 9: Add a handlerThe function send_Click will be called when a user click on the button

Add some content to the handler

Page 21: Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli  paul.guermonprez@intel.com Intel Software 2013-03-20.

Getting started with WPF?Step 9: Add a handlerIn WPF, if you define a name property to a control, you can access this one in the C# file by using its name (for example myInput for the Textbox and output for the Label here)

As you can see, adding a handler is easy and it is also quite simple to access the

view elements

Page 22: Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli  paul.guermonprez@intel.com Intel Software 2013-03-20.

Getting started with WPF?Step 10: Run your programPut a name in the Textbox and click on the Button

Page 23: Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli  paul.guermonprez@intel.com Intel Software 2013-03-20.

Conclusion

Page 24: Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli  paul.guermonprez@intel.com Intel Software 2013-03-20.

Conclusion

In this part, we’ve seen some basics about WPF You should be able to add some control and retrieve

inputs from the user nowWPF provides very efficient tools to design UI

WPF is simpleThe wysiwyg tool is adapted to UI creationVisual Studio allows us to be efficient

WPF is powerfulYou can access native librariesForced separation between the view and the rest of the application is a good practice

Page 25: Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli  paul.guermonprez@intel.com Intel Software 2013-03-20.
Page 26: Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli  paul.guermonprez@intel.com Intel Software 2013-03-20.

License Creative Commons – By 3.0

You are free:• to Share — to copy, distribute and transmit the work • to Remix — to adapt the work • to make commercial use of the work Under the following conditions:• Attribution — You must attribute the work in the manner specified by the author or licensor (but

not in any way that suggests that they endorse you or your use of the work).With the understanding that: • Waiver — Any of the above conditions can be waived if you get permission from the copyright

holder. • Public Domain — Where the work or any of its elements is in the public domain under applicable

law, that status is in no way affected by the license. • Other Rights — In no way are any of the following rights affected by the license:

– Your fair dealing or fair use rights, or other applicable copyright exceptions and limitations; – The author's moral rights; – Rights other persons may have either in the work itself or in how the work is used, such as publicity or

privacy rights. • Notice — For any reuse or distribution, you must make clear to others the license terms of this

work. The best way to do this is with a link to this web page.

http://creativecommons.org/licenses/by/3.0/