当前位置:网站首页>[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
边栏推荐
- Collect blog posts
- First knowledge of go language
- [registration] tf54: engineer growth map and excellent R & D organization building
- Nodejs installation and environment configuration
- Zhimeng dedecms security setup Guide
- 1-1 NodeJS
- Signalr can actively send data from the server to the client
- ClickHouse-数据类型
- 文件操作《二》(5000字总结篇)
- Solution architect's small bag - 5 types of architecture diagrams
猜你喜欢
oracle 中快速获取表的列名列表
Smart doc + Torna generate interface document
快时钟同步慢时钟域下的异步控制信号slow clk to fast clk
Path environment variable
org. apache. parquet. schema. InvalidSchemaException: A group type can not be empty. Parquet does not su
STM32__03—初识定时器
RTKLIB 2.4.3源码笔记
1-4 configuration executable script of nodejs installation
feign报400处理
Quick install mongodb
随机推荐
线性代数感悟之1
Handwritten event publish subscribe framework
websocket
ASP. Net core dependency injection service life cycle
ASP. Net core configuration options (Part 2)
First knowledge of go language
Customize my_ Strcpy and library strcpy [analog implementation of string related functions]
Paging the list collection
[registration] tf54: engineer growth map and excellent R & D organization building
Detailed explanation of C webpai route
[markdown notes]
Conversion between hexadecimal numbers
Input file upload
The new MySQL table has a self increasing ID of 20 bits. The reason is
Document operation II (5000 word summary)
Derivation of Σ GL perspective projection matrix
Baidu Map 3D rotation and tilt angle adjustment
线性代数感悟之2
SPC introduction
拷贝构造函数 浅拷贝与深拷贝