Windows Presentation Foundation Using C# (VS 2013)
Total Page:16
File Type:pdf, Size:1020Kb
Windows Presentation Foundation Using C#® (VS 2013) This course introduces Windows Presentation Foundation or WPF, the .NET technology from Microsoft for building rich Windows applications. It was originally part of .NET 3.0, previously called “WinFX” by Microsoft. WPF includes an XML-based markup language for defining program elements, Extensible Application Markup Language (XAML). WPF applications can be created using only code or a combination of code and XAML pages. This course covers the essentials of WPF, providing an orientation to this technology and a firm foundation for creating applications. The course is current to .NET 4.5.1 and Visual Studio 2013. WPF is a complex technology that can have a steep learning curve. This course approaches the subject in a practical manner, introducing the student to the fundamentals of creating Windows applications using the features of WPF. It includes coverage of both traditional concepts such as controls and new concepts such as XAML, flexible layout, logical resources, dependency properties, routed events, and the loosely-coupled command architecture of WPF. Data binding is discussed in detail, including visual data binding using Visual Studio 2013 and accessing databases using Entity Framework 6. Course Objectives: Gain an understanding of the philosophy and architecture of WPF. Create Windows applications using the classes provided by WPF. Understand the principles of XAML and create applications using a combination of code and XAML. Use the layout features of WPF to create flexible and attractive user interfaces. Implement event and command-driven applications with windows, menus, dialogs, toolbars, and other common user interface features. Use more advanced features of WPF such as dependency properties, routed events, logical resources, styles, templates, and data binding. Access databases using Visual Studio 2013 and the Entity Framework. Learn how to interoperate between WPF and Windows Forms Audience: NET programmers who want to be able to create rich Windows applications. Prerequisites: A working knowledge of C# and the .NET Framework. Number of Days: 4 days 1 Introduction to WPF XAML History of Microsoft GUI Controls Why WPF? Data Binding When Should I Use WPF? Appearance WPF and .NET Framework 3.0 Layout and Panels .NET Framework 4.0/4.5.1 Graphics Visual Studio 2013 Media Visual Studio Express 2013 Documents and Printing Target Framework Plan of Course WPF Core Types and Infrastructures Application and Window © Batky-Howell, LLC 1 Windows Presentation Foundation Using C# (VS 2013) Creating a Button TextBox Providing an Event Handler Initializing the TextBox Specifying Initial Input Focus Clipboard Support Complete First Program Items Controls Device-Independent Pixels Selector Controls Class Hierarchy Using a ListBox Content Property Multiple-Selection ListBox Simple Brushes Selected Items Panels Using the ComboBox Children of Panels Storing Objects in List Controls TwoControls – Code Collection Items in XAML Automatic Sizing 4 Layout 2 XAML Layout in WPF What is XAML? Controlling Size: Review Default Namespace Margin and Padding: Review XAML Language Namespace Thickness Structure: Review .NET Class and Namespace SizeDemo Program Elements and Attributes Top Panel XAML in Visual Studio 2013 Content Property Adding an Event Handler XAML vs. Code Layout in WPF Type Converter Controlling Size Alignment Margin and Padding Alignment inside a Stack Panel Thickness Structure Vertical Alignment Children of Panels Horizontal Alignment TwoControls – XAML Vertical Alignment in a Window Automatic Sizing Content Alignment TwoControls – Code FlowDirection Orientation Transforms Access Keys Panels Access Keys in XAML Shapes Content Property Size and Position Checked and Unchecked Events Attached Properties Property Element Syntax StackPanel Type Converters Children of StackPanel 3 WPF Controls WrapPanel Buttons in WPF DockPanel Using the Button Class Grid Toggle Buttons Using the Collections Editor IsThreeState Star Sizing CheckBox Grid ColumnSpan CheckBox Code Scrolling ToolTip Scaling RadioButton ScrollView and Viewbox Compared GroupBox 5 Dialogs Images Dialog Boxes in WPF © Batky-Howell, LLC 2 Windows Presentation Foundation Using C# (VS 2013) MessageBox Commands and Events MessageBox Show Method Images on Buttons Closing a Form: Review Tool Tips Common Dialog Boxes Other Elements on Toolbars Custom Dialogs Status Bars Modal Dialog 8 Dependency Properties and Routed New Product Dialog Events XAML for New Product Dialog Dependency Properties Code for the New Product Dialog Change Notification Bringing up the Dialog Property Value Inheritance Dialog Box Owner Support for Multiple Providers Displaying the Dialog Logical Trees Communicating with Parent Visual Tree XAML for Modeless Dialog Routed Events Handler for the Apply Button Event Handlers Handler for the Close Button Routing Strategies Instances of a Modeless Dialog Ready-made Routed Events in WPF Checking for an Instance 9 Resources 6 Menus and Commands Resources in .NET Menus in WPF Resources in WPF Menu Controls Binary Resources A Simple Menu Loose Files as Resources The Menu Using XAML Logical Resources Handling the Click Event Logical Resources in Code The Menu Using Procedural Code Static Resources Icons in Menus Dynamic Resources Context Menu 10 Data Binding XAML for Context Menu What is Data Binding? Separator Binding in Procedural Code Keyboard Shortcuts Binding in XAML Commands Binding to Plain .NET Properties WPF Command Architecture Binding to a Collection Command Bindings Controlling the Selected Item Custom Commands Data Context MenuCalculator Command Bindings Data Templates Input Bindings Specifying a Data Template Menu Items Value Converters Running MenuCalculator Using a Value Converter in XAML Checking Menu Items Collection Views Common Event Handlers Sorting Menu Checking Logic Grouping Calculation Logic Filtering Automatic Checking Collection Views in XAML 7 Toolbars and Status Bars Data Providers Toolbars in WPF ObjectDataProvider XAML for Toolbars XmlDataProvider © Batky-Howell, LLC 3 Windows Presentation Foundation Using C# (VS 2013) Data Access with Visual Studio 2013 SmallPub Database ADO.NET Entity Framework Add a Model using Database First Add a Data Source Navigation Code DataGrid Control Editing the Book Table Class Library Database Updates Refreshing the DataGrid 11 Styles, Templates, Skins and Themes WPF and Interfaces Styles Style Definition Applying Styles Style Inheritance Style Overriding Sharing Styles Types Styles Triggers Multiple Conditions Validation Templates Improving the Template Templated Parent’s Properties Respecting Visual States Using Templates with Styles Skins Changing Skins Themes 12 WPF and Windows Forms Interoperation Interoperating with Windows Forms Add a Form to a WPF Application Add a WPF Window to a Windows Forms Application Mixing WPF and Windows Forms in the Same Window Hosting a Windows Forms Control Using Code WindowsFormsHost via Code Windows Forms MonthCalendar WindowsFormsHost via XAML 13 Appendix A: Learning Resources © Batky-Howell, LLC 4 Windows Presentation Foundation Using C# (VS 2013) .