Transcript Win8 on Intel Programming Course
Win8 on Intel Programming Course Desktop : WPF Cédric Andreolli
www.Intel-Software-Academic-Program.com
Intel Software 2013-03-20
What is WPF?
What is WPF?
WPF: Windows Presentation Foundation
Renders graphical elements (through DirectX) Can be programmed with Visual Studio
The view
Written in XAML (Extensible Application Markup Language) Visual Studio provides a wysiwyg tool
The application core
Written in C#
What is WPF?
Native libraries
C# allows to use native libraries You sometimes need to write a wrapper
C# can access most of the WinRT library
WinRT offers a simple API Gives access to devices such as: Sensors GPS etc.
C# Wrapper C++ library
Getting started with WPF?
Getting started with WPF?
Step 1: Create a WPF project
In Visual Studio, create a new project (with a new solution) File -> New -> Project -> WPF Application
Getting started with WPF?
Step 2: Run your project
Click on the play button
Getting started with WPF?
Step 3: Open the XAML file
The file « MainWindow.xaml » is a XML file that represents the view Double click on it. The wysiwyg editor should open
Getting started with WPF?
Step 4: Display the Toolbox
The toolbox allows to add new controls in your view but… You must configure Visual Studio to display it!
Getting started with WPF?
Step 4: Display the Toolbox
You can change the Toolbox parent panel by Drag and Drop
Getting started with WPF?
Step 5: Add a label
Just drag and drop a Label from the Toolbox to the view
Getting started with WPF?
Step 6: Change the style
In the main view, select the label and open the Properties panel
Getting started with WPF?
Step 6: Change the style
If you can’t find the Properties panel, you will have to add it!
Getting started with WPF?
Step 6: Change the style
In 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.
Getting started with WPF?
Step 7: Add other UI elements
Add the following elements: An other Label A Textbox A Button An empty Label
Getting started with WPF?
Step 8: Add Name properties
A name allows to identify a field and to retrieve it in your program To retrieve the content of the Texbox, add a name propertie to your Texbox (Select the Textbox and click on the properties panel)
Getting started with WPF?
Step 8: Add Name properties
Add a name property to the output Label
Getting started with WPF?
Step 9: Add a handler
A handler intercepts the actions that come from the user Set the name property for the button (use « Click » for example)
Create the handler with Visual Studio
In the design view, double click on the button Visual Studio will create the handler for you The name of the handler will be send_Click button « Click ») (if you named you
Getting started with WPF?
Step 9: Add a handler
You should be automatically redirected to the C# file editor
Getting started with WPF?
Step 9: Add a handler
The function send_Click will be called when a user click on the button
Add some content to the handler
Getting started with WPF?
Step 9: Add a handler
In 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
Getting started with WPF?
Step 10: Run your program
Put a name in the Textbox and click on the Button
Conclusion
Conclusion
WPF is simple
The wysiwyg tool is adapted to UI creation Visual Studio allows us to be efficient
WPF is powerful
You can access native libraries Forced separation between the view and the rest of the application is a good practice
In this part, we’ve seen some basics about WPF You should be able to add some control and retrieve inputs from the user now WPF provides very efficient tools to design UI
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/