当前位置:网站首页>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 ~
边栏推荐
- Set up file server Minio for quick use
- Rumtime 1200 upgrade: London upgrade support, pledge function update and more
- Contenttype comparison of all types
- getInputStream() has already been called for this request
- 【入门】取近似值
- Yolov5进阶之六目标追踪环境搭建
- XX attack - reflective XSS attack hijacking user browser
- SQL number injection and character injection
- web254
- Microsoft stream - how to modify video subtitles
猜你喜欢
![[untitled]](/img/be/3523d0c14d555b293673af2b6fbcff.jpg)
[untitled]

window c盘满了

P4 安装bmv2 详细教程
![Thread safety analysis of [concurrent programming JUC] variables](/img/f9/a3604bec6f7e5317dd2c578da73018.jpg)
Thread safety analysis of [concurrent programming JUC] variables

Instead of houses, another kind of capital in China is rising

How to check ad user information?

【入门】取近似值

【华为机试真题详解】判断字符串子序列【2022 Q1 Q2 | 200分】

0 basic introduction to single chip microcomputer: how to use digital multimeter and precautions

Burpsuite -- brute force cracking of intruder
随机推荐
PostgreSQL source code learning (26) -- windows vscode remote debugging PostgreSQL on Linux
uni 热更新
Stack implementation calculator
empirical study and case study
[force deduction 10 days SQL introduction] Day10 control flow
[introduction] approximate value
[batch DOS CMD summary] extension variables - delay variables CMD /v:on, CMD /v:off, SETLOCAL enabledelayedexpansion, disabledelayedexpansion
一套十万级TPS的IM综合消息系统的架构实践与思考
Chinese font Gan: zi2zi
window c盘满了
Set up file server Minio for quick use
EDA open source simulation tool verilator beginner 6: debugging examples
web254
golang中的正则表达式使用注意事项与技巧
【力扣10天SQL入门】Day9 控制流
String coordinates of number to excel
事务方法调用@Transactional
SharePoint - how to quickly check whether SharePoint is standard or enterprise edition?
【入门】输入n个整数,输出其中最小的k个
Precautions and skills in using regular expressions in golang