Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Binding in GUI Application Development Patrick O’Brien.

Similar presentations


Presentation on theme: "Data Binding in GUI Application Development Patrick O’Brien."— Presentation transcript:

1 Data Binding in GUI Application Development Patrick O’Brien

2 Why use WPF? Design patterns Superiority to Windows Forms Collaboration with designers ▫ Expression Blend ▫ XAML

3 What is WPF? GUI development API released with.NET 3.0 Immediate predecessor is Windows Forms Built on top of DirectX

4 WPF Deployment Standalone XAML Typical -.exe XBAP ▫ Browser based

5 XAML (pronounced zammel) Extensible Application Markup Language ▫XML based Can be compiled or interpreted

6 Basic XAML

7

8 XAML vs. WinForms Problem: Implement a ComboBox with CheckBoxes as options in it Windows Forms: 600+ SLOC ▫ http://www.codeproject.com/Articles/21085/Ch eckBox-ComboBox-Extending-the-ComboBox- Class-and

9 XAML vs. WinForms

10 Windows Forms Controls Properties VS. Problems: Easy to get unorganized / inconsistent Number of lines requirements

11 Solution: XAML Styles Similar to CSS Keeps controls consistent without reusing code

12 XAML Styles To use this:

13 XAML Layouts Encourage dynamic layouts Several options ▫DockPanel ▫Grid ▫StackPanel ▫Canvas (not recommended)

14 XAML Layouts

15 WPF Events DockPanel Grid Button

16 Data Binding Bindings are inserted into XAML using extensions (curly braces) Can set bindings OneWay, TwoWay, OneTime DataContext provides a “starting point” for binding Path tells property what data to use

17 Data Binding Simple Example: Bind a Slider’s value to a TextBlock’s font size

18 Data Binding Bind fonts installed on a computer to a ListBox DataContext=“{x:Static Fonts.SystemFontFamilies}” Gets the fonts installed and sets them as the context for the ListBox Text=“{Binding Path=Count, Mode=OneTime}” Sets the tooltip for the list box to display the number of fonts installed

19 Advanced Data Binding Converting phone numbers in TextBoxes

20 PhoneConverter : IValueConverter

21 ContactListView

22 Design Patterns MVC – Model View Controller ▫ Unfit for WPF MVP – Model View Presenter ▫ Model – Data (Contact, Address, etc.) ▫ View – Seen by the user ▫ Presenter – Handles communication between Model and View

23 MVP Each View will have a corresponding Presenter ApplicationPresenter represents the application as a whole ▫ Individual Presenters use an instance of ApplicationPresenter to interact with controls

24 ContactListView.xaml.cs

25 ContactListPresenter.cs

26 Questions?


Download ppt "Data Binding in GUI Application Development Patrick O’Brien."

Similar presentations


Ads by Google