Introduced
Re-imagine the bindings of Windows 8 Store Apps
Binding with ObservableCollection
Binding with CollectionViewSource
Binding with Virtualizedfilesvector
Binding to Virtualizeditemsvector
Example
1, show how to bind observablecollection<t> type of data
Binding/bindingobservablecollection.xaml
<page x:class= "XamlDemo.Binding.BindingObservableCollection" xmlns= "http://schemas.microsoft.com/winfx/2006/x
Aml/presentation "xmlns:x=" Http://schemas.microsoft.com/winfx/2006/xaml "xmlns:local=" using:XamlDemo.Binding " Xmlns:d= "http://schemas.microsoft.com/expression/blend/2008" xmlns:mc= "http://schemas.openxmlformats.org/ markup-compatibility/2006 "mc:ignorable=" D "> <grid background=" Transparent "> <grid Margin = "0 0" > <Grid.Resources> <datatemplate x:key= "Mydatatempla
TE "> <border background=" Blue "width=" cornerradius= "3" horizontalalignment= "left" >
<textblock text= "{Binding Name}" fontsize= "14.667"/> </Border> </DataTemplate> </Grid.Resources> <stackpanel Orient ation= "Horizontal" verticalalignment= "Top "> <button name=" btndelete "content=" delete a record "click=" Btndelete_click_1 "/> &L T Button Name= "btnupdate" content= "update a record" click= "Btnupdate_click_1" margin= "0 0 0"/> </STACKPANEL&G
T <listview x:name= "ListView" itemtemplate= "{StaticResource mydatatemplate}" margin= "0 0 0"/> </ Grid> </Grid> </Page>
Binding/bindingobservablecollection.xaml.cs
* * Demonstrates how to bind observablecollection<t> type of data * * observablecollection<t>-Provide notification when data collection is added, deleted, updated, moved items, and so on
* CollectionChanged-Events (Event parameters: NotifyCollectionChangedEventArgs) that are triggered when adding items, deleting items, updating items, moving items, or using System;
Using System.Collections.ObjectModel;
Using System.Collections.Specialized;
Using System.Linq;
Using Windows.UI.Xaml;
Using Windows.UI.Xaml.Controls;
Using Xamldemo.model; Namespace Xamldemo.binding {public sealed partial class Bindingobservablecollection:page {private Obse
Rvablecollection<employee> _employees; Public Bindingobservablecollection () {this.
InitializeComponent (); This.
Loaded + = bindingobservablecollection_loaded; } void Bindingobservablecollection_loaded (object sender, RoutedEventArgs e) {_employees
= New Observablecollection<employee> (Testdata.getemployees ()); _employees. CollectionChanged + = _employees_collectionchanged;
Listview.itemssource = _employees;
} void _employees_collectionchanged (object sender, NotifyCollectionChangedEventArgs e) { * * E.action-the type of action that raises this event (NotifyCollectionChangedAction enum) * Add, Remove, Replace, move, R ESET * E.olditems-remove, replace, move operation data list * E.oldstartingindex-remove, replace, Mov
Index * e.NewItems at occurrence of e operation-new list of data involved in the change * e.newstartingindex-index of the occurrence of the new list of data involved in the change */} private void Btndelete_click_1 (object sender, RoutedEventArgs e) {_employe Es.
RemoveAt (0); } private void Btnupdate_click_1 (object sender, RoutedEventArgs e) {Random Random = new
Random (); The notification here comes from the Employee _employees that implements the INotifyPropertyChanged interface. A (). Name = random. Next (1000, 10000). ToSTring (); The notification here comes from observablecollection<t> _employees[1] = new Employee () {Name = random. Next (1000, 10000).
ToString ()}; }
}
}