last lecture data binding, binding object markup extension bind to any prop with...
TRANSCRIPT
![Page 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](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e635503460f94b5fd67/html5/thumbnails/1.jpg)
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
![Page 2: Last lecture data binding, binding object markup extension bind to any prop with INotifyPropertyChanged, target must be dep. prop. bind to obj... so no](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e635503460f94b5fd67/html5/thumbnails/2.jpg)
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.
![Page 3: Last lecture data binding, binding object markup extension bind to any prop with INotifyPropertyChanged, target must be dep. prop. bind to obj... so no](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e635503460f94b5fd67/html5/thumbnails/3.jpg)
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
![Page 4: Last lecture data binding, binding object markup extension bind to any prop with INotifyPropertyChanged, target must be dep. prop. bind to obj... so no](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e635503460f94b5fd67/html5/thumbnails/4.jpg)
![Page 5: Last lecture data binding, binding object markup extension bind to any prop with INotifyPropertyChanged, target must be dep. prop. bind to obj... so no](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e635503460f94b5fd67/html5/thumbnails/5.jpg)
•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
![Page 6: Last lecture data binding, binding object markup extension bind to any prop with INotifyPropertyChanged, target must be dep. prop. bind to obj... so no](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e635503460f94b5fd67/html5/thumbnails/6.jpg)
•custom or builtin
•can use a valueconverter
•and pass to ctor
![Page 7: Last lecture data binding, binding object markup extension bind to any prop with INotifyPropertyChanged, target must be dep. prop. bind to obj... so no](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e635503460f94b5fd67/html5/thumbnails/7.jpg)
![Page 8: Last lecture data binding, binding object markup extension bind to any prop with INotifyPropertyChanged, target must be dep. prop. bind to obj... so no](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e635503460f94b5fd67/html5/thumbnails/8.jpg)
•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
![Page 9: Last lecture data binding, binding object markup extension bind to any prop with INotifyPropertyChanged, target must be dep. prop. bind to obj... so no](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e635503460f94b5fd67/html5/thumbnails/9.jpg)
filtering
•a property Filter of type Predicate<Object> its null by d
•e.g. show only photos from last 7 days
![Page 10: Last lecture data binding, binding object markup extension bind to any prop with INotifyPropertyChanged, target must be dep. prop. bind to obj... so no](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e635503460f94b5fd67/html5/thumbnails/10.jpg)
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)
![Page 11: Last lecture data binding, binding object markup extension bind to any prop with INotifyPropertyChanged, target must be dep. prop. bind to obj... so no](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e635503460f94b5fd67/html5/thumbnails/11.jpg)
![Page 12: Last lecture data binding, binding object markup extension bind to any prop with INotifyPropertyChanged, target must be dep. prop. bind to obj... so no](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e635503460f94b5fd67/html5/thumbnails/12.jpg)
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
![Page 13: Last lecture data binding, binding object markup extension bind to any prop with INotifyPropertyChanged, target must be dep. prop. bind to obj... so no](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e635503460f94b5fd67/html5/thumbnails/13.jpg)
additional views•CollectionViewSource can be used to create
new views and applied to targets
•binding paths
•remain same
![Page 14: Last lecture data binding, binding object markup extension bind to any prop with INotifyPropertyChanged, target must be dep. prop. bind to obj... so no](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e635503460f94b5fd67/html5/thumbnails/14.jpg)
•CollectionViewSource has its own SortDescriptions and GroupDescriptions properties and a Filter event to be used from xaml
•must include another namespace
![Page 15: Last lecture data binding, binding object markup extension bind to any prop with INotifyPropertyChanged, target must be dep. prop. bind to obj... so no](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e635503460f94b5fd67/html5/thumbnails/15.jpg)
•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
![Page 16: Last lecture data binding, binding object markup extension bind to any prop with INotifyPropertyChanged, target must be dep. prop. bind to obj... so no](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e635503460f94b5fd67/html5/thumbnails/16.jpg)
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
![Page 17: Last lecture data binding, binding object markup extension bind to any prop with INotifyPropertyChanged, target must be dep. prop. bind to obj... so no](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e635503460f94b5fd67/html5/thumbnails/17.jpg)
XmlDataProvider
![Page 18: Last lecture data binding, binding object markup extension bind to any prop with INotifyPropertyChanged, target must be dep. prop. bind to obj... so no](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e635503460f94b5fd67/html5/thumbnails/18.jpg)
•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
![Page 19: Last lecture data binding, binding object markup extension bind to any prop with INotifyPropertyChanged, target must be dep. prop. bind to obj... so no](https://reader035.vdocuments.site/reader035/viewer/2022062516/56649e635503460f94b5fd67/html5/thumbnails/19.jpg)
•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