当前位置:网站首页>[WPF binding 3] listview basic binding and data template binding
[WPF binding 3] listview basic binding and data template binding
2022-04-23 17:08:00 【code bean】
【WPF binding 1】 ListBox Basic binding
It introduces ListBox Basic binding of , Record today ListView Related binding of .
if ListBox It's a list , that ListView It's a multi list with column headings .
Such as :
This list has a feature , The first and second columns are strings , The third column is a control TextBox.
So today we will use two kinds of bindings , Basic binding and template binding (DataTemplate)
Basic binding and ListBox similar ,ListBox Yes DisplayMemberPath attribute
<ListBox Name="list_axis" DisplayMemberPath="Name" SelectedValuePath="Num" SelectionChanged="list_axis_SelectionChanged"/>
ListView There is an attribute called DisplayMemberBinding, Because there is more than one column , So we need to make a dolly , like this :
<ListView x:Name="lv_pos" ItemContainerStyle="{StaticResource ListViewItemStyle}">
<ListView.View>
<GridView>
<GridViewColumn Header=" name " Width="auto" DisplayMemberBinding="{Binding Name}"/>
<GridViewColumn Header=" Alias " Width="auto" DisplayMemberBinding="{Binding ShowName}"/>
</GridView>
</ListView.View>
</ListView>
The third column , I use it Textbox Control , This supports editing , Therefore, template binding is required , like this :
<ListView x:Name="lv_pos" ItemContainerStyle="{StaticResource ListViewItemStyle}">
<ListView.View>
<GridView>
<GridViewColumn Header=" name " Width="auto" DisplayMemberBinding="{Binding Name}"/>
<GridViewColumn Header=" Alias " Width="auto" DisplayMemberBinding="{Binding ShowName}"/>
<GridViewColumn Header=" Location " Width="120">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Width="auto" MinWidth="80" Text="{Binding Path=Pos, Mode=TwoWay}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
Finally, let's look at the data source section :
First customize a class :
public class AxisPosInfo
{
public AxisPosInfo(string name, string show_name, double pos)
{
Name = name;
ShowName = show_name;
Pos = pos;
}
public AxisPosInfo()
{
}
public string Name { get; set; }
public string ShowName { get; set; }
public double Pos { get; set; }
}
Define an array in the :
public List<AxisPosInfo> PosList { get; set; }
The use of ListView Of ItemsSource Bind with data source .
lv_pos.ItemsSource = axis_info.PosList;
版权声明
本文为[code bean]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231702084890.html
边栏推荐
- _ Mold_ Board_
- Summary of common websites
- Baidu Map Case - modify map style
- Nacos + aspnetcore + Ocelot actual combat code
- 1-4 configuration executable script of nodejs installation
- [PROJECT] small hat takeout (8)
- Detailed explanation of the penetration of network security in the shooting range
- org. apache. parquet. schema. InvalidSchemaException: A group type can not be empty. Parquet does not su
- [problem solving] [show2012] random tree
- 线性代数感悟之2
猜你喜欢
Signalr can actively send data from the server to the client
ASP. NET CORE3. 1. Solution to login failure after identity registers users
Go language, array, string, slice
Shell脚本——Shell编程规范及变量
CentOS MySQL multi instance deployment
Path environment variable
Further study of data visualization
Sub database and sub table & shardingsphere
STM32__03—初识定时器
Scope and scope chain in JS
随机推荐
Solution architect's small bag - 5 types of architecture diagrams
PHP efficiently reads large files and processes data
Further study of data visualization
. net cross platform principle (Part I)
快时钟同步慢时钟域下的异步控制信号slow clk to fast clk
Detailed explanation of Niuke - Gloves
How to implement distributed locks with redis?
Use of shell awk command
Rtklib 2.4.3 source code Notes
Deep understanding of control inversion and dependency injection
Input file upload
ClickHouse-SQL 操作
Nodejs reads the local JSON file through require. Unexpected token / in JSON at position appears
Linux MySQL data timing dump
Nifi fast installation and file synchronization
BUG_ me
Shell-sed命令的使用
Shell脚本——Shell编程规范及变量
文件操作《二》(5000字总结篇)
1-2 JSX syntax rules