ADO Data Binding

Source: Internet
Author: User

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Linq;usingSystem.Text;usingSystem.Windows;usingSystem.Windows.Controls;usingSystem.Windows.Data;usingSystem.Windows.Documents;usingSystem.Windows.Input;usingSystem.Windows.Media;usingSystem.Windows.Media.Imaging;usingSystem.Windows.Navigation;usingSystem.Windows.Shapes;namespaceWPF data Binding {/// <summary>    ///the interactive logic of MainWindow.xaml/// </summary>     Public Partial classMainwindow:window {Privateperson P1 =NewPerson ();  PublicMainWindow () {InitializeComponent (); }        Private voidWindow_Loaded (Objectsender, RoutedEventArgs e) {P1. Age= -; P1. Name="Tony Leung"; Grid1. DataContext=P1; }        Private voidButton1_Click (Objectsender, RoutedEventArgs e) {MessageBox.Show (p1). Age.tostring ()+P1.        Name); }        Private voidButton2_Click (Objectsender, RoutedEventArgs e) {P1. Age++; P1. Name="Takeshi Kaneshiro"; }    }    classperson:inotifypropertychanged { Public EventPropertyChangedEventHandler propertychanged; Private intAge ; Private stringname;  Public stringName {Get            {                returnname; }            Set            {                 This. Name =value; if(PropertyChanged! =NULL) {propertychanged ( This,NewPropertyChangedEventArgs ("Name")); }            }        }         Public intAge {Get            {                returnAge ; }            Set            {                 This. age=value; if(PropertyChanged! =NULL) {propertychanged ( This,NewPropertyChangedEventArgs (" Age")); }            }        }    }}

Also in the foreground in the control you want to bind to write such as: text= "{Binding Name}"

Generally not directly write Textbox_1.text=p1. Name is to avoid manipulating controls directly.

ADO Data Binding

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.