Presentation is loading. Please wait.

Presentation is loading. Please wait.

Last lecture data binding, binding object markup extension bind to any prop with INotifyPropertyChanged, target must be dep. prop. bind to obj... so no.

Similar presentations


Presentation on theme: "Last lecture data binding, binding object markup extension bind to any prop with INotifyPropertyChanged, target must be dep. prop. bind to obj... so no."— Presentation transcript:

1 Last lecture data binding, binding object markup extension bind to any prop with INotifyPropertyChanged, target must be dep. prop. bind to obj... so no prop. path binding to collection issynchronized with current item datacontext displaymemberpath, stringformat, datatemplate, valueconverter

2 customizing collection view when isSynchronizedWithCurrentItem= true, where is the current item a default “view” inserted... obj impl ICollectionView... has also support for sorting, grouping, filtering, and navigating lets discuss these four and multiple views for the same source obj.

3 sorting SortDescriptions prop. is a coll. of SortDescription which chooses a field and order sort by datetime, then by name a clear method to return to unsorted eg. three buttons to sort and toggle

4

5 no explicit relationship with ListBox if additional controls bound, they would sort with it Now a GroupDescriptions prop. containing PropertyGroupDescription obj. but it has no effect without the GroupStyle prop. set with a HeaderTemplate

6 custom or builtin can use a valueconverter and pass to ctor

7

8 sorting applied before grouping first sorting criteria should be same as grouping otherwise output doesnt make much sense can pass null to get total custom control in the value converter

9 filtering a property Filter of type Predicate its null by d e.g. show only photos from last 7 days

10 navigating nav. means managing the current item, not the other kind of nav. ICollectionView has CurrentItem CurrentPosition and also methods for changing them e.g. prev/next photo buttons are handled like this view initializes to 0 and first item listbox initializes to -1 and null (unselected)

11

12 prop. paths in Bindings useful for master/detail interfaces sorting, grouping, filtering automatic but nav. only when IsSynchronizedWithCurrentItem=true otherwise SelectedItem and CurrentItem are separate

13 additional views CollectionViewSource can be used to create new views and applied to targets binding paths remain same

14 CollectionViewSource has its own SortDescriptions and GroupDescriptions properties and a Filter event to be used from xaml must include another namespace

15 IsSynchronizedWithCurrentItem=true by d for custom views... have to explicitly set false... kind of a bit inconsistent... but we acknowledging view existance by custom view

16 Data Providers source obj can be arbitrary... you could bind to db, registry, excel spreadsheet etc. with enough code an obj. that exposes right props and notifications and handles messy details work involved might overweight benefits if writing all logic yourself two generic data-binding-friendly way to expose common items... XmlDataProvider and ObjectDataProvider starting with wpf 3.5 sp1... data binding works with LINQ (language independent query)... you can set Source or DataContext to a LINQ and the enumerable result used Now with LINQ to SQL and LINQ to XML, is an easy way than using wpf data providers

17 XmlDataProvider

18 xData to avoid compiler errors namespace pollution avoided with xmlns=”” Binding’s XPath prop used rather than Path if external file, even easier “GameStat/@Type” would fill list with each GameStat’s Type attribute

19 data provided in XmlNode etc... objects from System.Xml so you can use Path and XPath together needs hierarchical data template if you want to bind to xml tree


Download ppt "Last lecture data binding, binding object markup extension bind to any prop with INotifyPropertyChanged, target must be dep. prop. bind to obj... so no."

Similar presentations


Ads by Google