当前位置:网站首页>C basic knowledge review (Part 4 of 4)
C basic knowledge review (Part 4 of 4)
2022-07-01 08:19:00 【ErrorError!】
The first 9 Chapter Data binding
Catalog
9.1 Basic concepts of data binding
WPF Three data binding technologies are provided :Binding、MultiBinding、PriorityBinding
These three Binding The base classes of are BindingBase, and BindingBase Inherited from MarkupExtension
stay WPF in ,ContentControl( Such as Button) and ItemsControl( Such as ListBox and ListView) Both provide built-in functions , Enable flexible data binding for a single data item or a collection of data items , And can generate sorting 、 Filtered and grouped views
System.Windows.Data.Binding class :
take **“ The goal is ” Additional properties of And data “ Source ” Properties of ** Bind together , The data source can be any modifier of public Properties of
Binding syntax :
<object property="{Binding declaration}" .../>
//object For binding targets ;declaration Declare for binding , If there are multiple binding declarations , The binding declarations are separated by commas
<Slider Name="slide1" Maximum="100" />
<TextBlock Text="{Binding ElementName=slide1,Path=Value}" />
9.1.1 Binding and binding expressions
Binding means to bind “ The goal is ” The dependency property of is bound to “ Source ” Of CLR attribute

BindingExpression It is to maintain the connection between the binding source and the binding target Connect Based on , One Binding An instance can contain multiple BindingExpression example
9.1.2 Binding mode (Mode attribute )
1、OneWay: One way binding
characteristic : When the source changes, the target changes automatically , This is applicable when the bound control is an implicit read-only control ( Student ID ), Or there is no control interface for the target property to change ( Such as the background color of the table )
<TextBlock Text="{Binding ElementName=listBox1, Path=SelectedItem.Content, Mode=OneWay}"/>
2、TwoWay: Two way binding
characteristic : When one of the sources or targets changes , The other side also changes automatically , For editable or interactive UI programme
<TextBox Text="{Binding ElementName=listBox2, Path=SelectedItem.Content, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
3、OneTime: Single bind
characteristic : When an application Program started or Data context (DataContext) A change has taken place Update the target only when , After that, the change of source will no longer affect the target , For binding static data , It's essentially OneWay The binding of Simplified form
<TextBox Text="{Binding ElementName=listBox3, Path=SelectedItem.Content, Mode=OneTime}" />
4、OneWayToSource: Reverse binding
characteristic : When the target changes, the source also changes , In this way OneWay Binding is just the opposite
<TextBox Text="{Binding ElementName=listBox4, Path=SelectedItem.Content, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}" />
5、Default: Automatic access to Target properties Default Mode value
If the binding mode is not declared , The default is Default, In general , Editable Control properties ( Such as the properties of text boxes and check boxes ) The default is two-way binding , and Most other genera Sex defaults to one-way binding
<TextBox Text="{Binding ElementName=listBox2, Path=SelectedItem.Content, Mode=Default, UpdateSourceTrigger=LostFocus}" />
9.1.3 Control when the source is updated (UpdateSourceTrigger)
Explicit: use C# Code calls BindingExpression Of UpdateSource Method to update the source
LostFocus: Automatically update the source when the target control loses focus
PropertyChanged: Every time the binding property of the target control changes, it will automatically update the source
<TextBox Text="{Binding ElementName=listBox2,
Path=SelectedItem.Content,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" />
9.1.4 Binding path syntax (Path attribute )
(1)Path The value of is the attribute name of the source object ( Commonly used , Examples in this chapter )
(2)Path Value :
(a) When binding to additional attributes , It needs to be enclosed in parentheses
(b) Specify the attribute indexer with square brackets , You can also use nested indexers .
(c) Inside the indexer , You can use multiple indexer parameters separated by commas , You can also use parentheses to specify the type of each parameter
(d) If the source is a collection view , You can use a slash (/) Specifies the current item
(e) You can use points (.) The path is bound to the current source
9.1.5 Data conversion
use XAML When describing data binding ,WPF The provided type converter can convert some types of values to string representation . But in some cases , Developers may need to customize the converter
for example , When the bound source object is of type DateTime Properties of , under these circumstances , In order for the binding to work properly , You need to convert the attribute value to a custom string representation first
To associate a converter with a binding , Generally, create an implementation first IValueConverter The class of the interface , Then implement two methods :Convert Methods and ConvertBack Method
9.2 Simple data binding
9.2.1 Specify the binding source directly in a single attribute
ElementName: The source is another WPF Elements
<Slider Name="slide1" Width="100" Maximum="100" />
<Rectangle Width="{Binding ElementName=slide1,Path=Value}" Height="15" Fill="Red" />
Souce: The source is one. CLR object
<Page …… xmlns:src="clr-namespace:ch11.Examples">
<TextBlock Text="{Binding XueHao, Source={StaticResource info}}" />
use Source Bound to the CLR object
Binding Class Source Property indicates that the bound data source is CLR object , The CLR The object can be either .NET Instances of classes provided by the framework , It can also be an instance of a custom class
use RelativeSource Bind relative target
RelativeSource: The source and target are the same element
RelativeSource Express “ Source ” It's self . When you bind a property of an object to another property of its own , Or in style (Style) Or template (ControlTemplate) When using data binding in ,RelativeSource Attributes are useful
<Rectangle Width="100" Height="{Binding RelativeSource={RelativeSource Self}, Path=Width}" />
9.2.2 adopt DataContext Bind multiple attributes to the same source
(1) Just use on the parent element DataContext Declare once
(2) Of each sub element “Bingding Path=…” Can be omitted as : “Bingding …”
The first 10 Chapter Database and entity data model
10.1 Create databases and tables
10.1.1 ADO.NET Data access technology
1、 utilize DataSet Access database
This is a ADO.NET The technology provided at the time of Launch , Used in disconnect Data processing under the mode , The technology will reside in native memory DataSet As the middle layer , Applications and DataSet Interact ,DataSet And then interact with the database
2、 utilize LINQ to DataSet Access database
In this way , Applications can use LINQ grammar visit DataSet, Usage is more flexible than the first method , It's simpler
3、 utilize LINQ to SQL Access database
This method is directly related to SQL Server Database interaction , High execution efficiency , Fast , But this method does not support other types of databases , stay LINQ to SQL in , First use of O/R Designer build model , Then use this model to transfer SQL sentence , perform SQL command , It can also be used. LINQ Syntax direct access SQL Server
When using this technology , It is generally used to design customized middle tier object models ( middleware ), Then make it .dll File for other applications to call
4、 utilize EF and LINQ to Entities Access database ( Recommend ways )
This is the recommended way to access the database , This model can support many types of databases ( Include SQL Server、Oracle、DB2、MySQL etc. ), And the database access engine of the model can be directly provided by the database supplier
10.1.2 SQL Server 2014 brief introduction
SQL Server 2014 The main features of the database engine :
(1) Provides... For operating system upgrades AlwaysOn Cross cluster migration of availability groups
(2) Enhancements for programmability
(3) Enhancements for scalability and performance
(4) It provides support for cloud computing and big data
10.1.3 establish LocalDB database
LocalDB brief introduction : be based on service The database of , But it can only be accessed locally
advantage : Simple to use , And when copying projects and databases from one computer to another , No modification required
Access through the application LocalDB Database time ,VS2015 Meeting The .mdf File attachment To LocalDB Of Default instance in , When the database is no longer used ,LocalDB It will be .mdf File from the Default instance in Automatic separation come out
stay VS The basic usage of directly creating a database in :
Method 1 : choice 【 Service based database 】 Create database directly (MyDb.mdf)

Method 2 :
(1) choice 【ADO.NET Entity data model 】

(2) choice 【 From database Code First】


10.2 Use Entity Framework to create entity data model
10.2.1 Basic concepts of Entity Framework

Advantages of Entity Framework :
(1) Applications can be modeled through concepts ( Including inheritance 、 Types of complex members and relationships ) Come to work
(2) Applications no longer have hard coded dependencies on specific data engines or storage architectures
(3) You can change the mapping between the conceptual model and the storage specific schema without changing the application code
(4) Developers can use to map to a variety of storage architectures ( May be implemented in different database management systems ) A consistent application object model
(5) Multiple conceptual models can be mapped to the same storage architecture
10.2.2 Entity Framework development pattern

1、 Database first (Database First)
Create the database first , Then manually generate the corresponding... According to the database Entity data model (.edmx file ), The database structure has changed , The model must be generated again manually
2、 Model first (Model First)
First, use the template provided by the development tool to create the entity data model (.edmx file ), Then the database is generated according to the entity data model
3、 Code first (Code First, Suggested techniques )
【 actual 】 Write first Data model class , And then generate database
【 Reference resources 】 Create the database first , Then generate entity data model classes , This method is only used to generate reference code
If the article helps you , Remember to support three times with one click ~
边栏推荐
- Day5: scanner object, next() and nextline(), sequential structure, selection structure, circular structure
- 程序员养生宝典
- 软键盘高度报错
- [force deduction 10 days SQL introduction] Day10 control flow
- golang中的正则表达式使用注意事项与技巧
- 使用 setoolkit 伪造站点窃取用户信息
- [redis] it takes you through redis installation and connection at one go
- php laravel微信支付
- Embedded-c language-10-enumeration / (function) pointer (function) / multi-level pointer /malloc dynamic allocation / file operation
- Keithley 2100 software 𞓜 Keithley2400 test software ns SourceMeter
猜你喜欢

Principle and process of embossing

Use threejs simple Web3D effect

SharePoint - modify web application authentication using PowerShell

Five combination boxing, solving six difficult problems on campus and escorting the construction of educational informatization

On several key issues of digital transformation

【华为机试真题详解】判断字符串子序列【2022 Q1 Q2 | 200分】
![[getting started] enter the integer array and sorting ID, and sort its elements in ascending or descending order](/img/87/07783593dbabcf29700fa207ecda08.png)
[getting started] enter the integer array and sorting ID, and sort its elements in ascending or descending order

Learn reptiles for a month and earn 6000 a month? Tell you the truth about the reptile, netizen: I wish I had known it earlier

Access report realizes subtotal function

CPU design practice - Chapter 4 practical tasks - simple CPU reference design and debugging
随机推荐
Instead of houses, another kind of capital in China is rising
How can beginners correctly understand Google's official suggested architectural principles (questions?)
Chinese font Gan: zi2zi
[getting started] intercepting strings
Access report realizes subtotal function
OJ input and output exercise
How to troubleshoot SharePoint online map network drive failure?
Aardio - Method of self constructed geticonhandle
Day5: scanner object, next() and nextline(), sequential structure, selection structure, circular structure
[dynamic planning] p1020 missile interception (variant of the longest increasing subsequence)
[untitled]
【华为机试真题详解】判断字符串子序列【2022 Q1 Q2 | 200分】
Gdip - hatchbrush pattern table
slice扩容机制分析
防“活化”照片蒙混过关,数据宝“活体检测+人脸识别”让刷脸更安全
Airsim radar camera fusion to generate color point cloud
【入门】取近似值
Anddroid text to speech TTS implementation
Koltin35, headline Android interview algorithm
uni 热更新