Windows 8 Store Apps Learning (53) binding

Source: Internet
Author: User
Tags bind tostring xmlns

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"/> &LT;/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 ()}; }
    }
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.