当前位置:网站首页>[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
边栏推荐
- SPC introduction
- Shell script -- shell programming specification and variables
- 1-5 nodejs commonjs specification
- Installing labellmg tutorial in Windows
- Generation of barcode and QR code
- PostgreSQL column storage and row storage
- Calculate pie chart percentage
- groutine
- Use between nodejs modules
- Shell脚本——Shell编程规范及变量
猜你喜欢
1-1 NodeJS
Lock lock
Nodejs installation and environment configuration
. net cross platform principle (Part I)
Go language, array, string, slice
[PROJECT] small hat takeout (8)
文件操作《二》(5000字总结篇)
Detailed explanation of the penetration of network security in the shooting range
JS, entries(), keys(), values(), some(), object Assign() traversal array usage
TypeError: set_ figure_ params() got an unexpected keyword argument ‘figsize‘
随机推荐
Nacos + aspnetcore + Ocelot actual combat code
Shell-awk命令的使用
◰ GL shadow map core steps
Idea of batch manufacturing test data, with source code
RTKLIB 2.4.3源码笔记
[pimf] openharmony paper Club - what is the experience of wandering in ACM survey
ASP. Net core configuration options (Part 2)
Promise (II)
线性代数感悟之1
On lambda powertools typescript
freeCodeCamp----prob_ Calculator exercise
Shell脚本——Shell编程规范及变量
1-1 NodeJS
About stream flow, write it down briefly------
Generation of barcode and QR code
An essay on the classical "tear down the wall in thinking"
Devexpress GridView add select all columns
. net type transfer
STM32__03—初识定时器
Lock锁