Introduction to the second part of WPF (1)

Source: Internet
Author: User

Part 2 travel to the internal world of WPF

Chapter 2 Introduction to Binding

6.1 status of Data Binding in WPF

Applications have a three-tier structure, namely the data storage layer, data processing layer, and data presentation layer. The storage layer is equivalent to a city's storage zone, which consists of a database and a file system. The processing layer should be called the logic layer more correctly, algorithms related to business logic and used for data processing are concentrated here; the function of the presentation layer is to display processed data to users through a visual interface or other types of interfaces to other applications.

The essence of a program is the data plus algorithm.

6.2 Binding Basics


[Csharp]
Using System. ComponentModel;
 
Namespace FirstWpfApplication. Objects
{
Class Student: INotifyPropertyChanged
{
Private string name;
Public string Name
{
Get {return this. name ;}
Set
{
This. name = value;
// Trigger the System. ComponentModel. INotifyPropertyChanged. PropertyChanged event
PropertyChanged. Invoke (this, new PropertyChangedEventArgs ("Name "));
}
}
 
Public event PropertyChangedEventHandler PropertyChanged;
}
}

Using System. ComponentModel;

Namespace FirstWpfApplication. Objects
{
Class Student: INotifyPropertyChanged
{
Private string name;
Public string Name
{
Get {return this. name ;}
Set
{
This. name = value;
// Trigger the System. ComponentModel. INotifyPropertyChanged. PropertyChanged event
PropertyChanged. Invoke (this, new PropertyChangedEventArgs ("Name "));
}
}

Public event PropertyChangedEventHandler PropertyChanged;
}
}

[Html]
<Grid>
<Grid. RowDefinitions>
<RowDefinition Height = "25"/>
<RowDefinition Height = "5"/>
<RowDefinition Height = "25"/>
<RowDefinition Height = "5"/>
<RowDefinition Height = "25"/>
</Grid. RowDefinitions>
<TextBox x: Name = "textBox1" BorderBrush = "Black" Grid. Row = "0"/>
<TextBox x: Name = "textBox2" BorderBrush = "Black" Grid. Row = "2"/>
<Button x: Name = "button1" Content = "OK" Click = "button#click" Grid. Row = "4"/>
</Grid>

<Grid>
<Grid. RowDefinitions>
<RowDefinition Height = "25"/>
<RowDefinition Height = "5"/>
<RowDefinition Height = "25"/>
<RowDefinition Height = "5"/>
<RowDefinition Height = "25"/>
</Grid. RowDefinitions>
<TextBox x: Name = "textBox1" BorderBrush = "Black" Grid. Row = "0"/>
<TextBox x: Name = "textBox2" BorderBrush = "Black" Grid. Row = "2"/>
<Button x: Name = "button1" Content = "OK" Click = "button#click" Grid. Row = "4"/>
</Grid>
[Csharp]
Public partial class MainWindow: Window
{
Student stu;
 
Public MainWindow ()
{
InitializeComponent ();
 
Stu = new Student ();
 
Binding binding = new Binding ();
Binding. Source = stu;
Binding. Path = new PropertyPath ("Name ");
 
BindingOperations. SetBinding (this. textBox1, TextBox. TextProperty, binding );
}
 
Private void button#click (object sender, RoutedEventArgs e)
{
Stu. Name = textBox2.Text;
}
}

Public partial class MainWindow: Window
{
Student stu;

Public MainWindow ()
{
InitializeComponent ();

Stu = new Student ();

Binding binding = new Binding ();
Binding. Source = stu;
Binding. Path = new PropertyPath ("Name ");

BindingOperations. SetBinding (this. textBox1, TextBox. TextProperty, binding );
}

Private void button#click (object sender, RoutedEventArgs e)
{
Stu. Name = textBox2.Text;
}
}

 

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.