当前位置:网站首页>[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
边栏推荐
猜你喜欢
Shell script -- shell programming specification and variables
Detailed explanation of the penetration of network security in the shooting range
Milvus 2.0 détails du système d'assurance de la qualité
【生活中的逻辑谬误】稻草人谬误和无力反驳不算证明
STM32__ 03 - beginner timer
Signalr can actively send data from the server to the client
. net cross platform principle (Part I)
CentOS MySQL multi instance deployment
Bytevcharts visual chart library, I have everything you want
Derivation of Σ GL perspective projection matrix
随机推荐
拷贝构造函数 浅拷贝与深拷贝
Baidu Map 3D rotation and tilt angle adjustment
Linux MySQL data timing dump
Solution architect's small bag - 5 types of architecture diagrams
Paging SQL
Nodejs reads the local JSON file through require. Unexpected token / in JSON at position appears
Shell-入门、变量、以及基本的语法
. net type transfer
Idea of batch manufacturing test data, with source code
Getting started with JDBC
Error in v-on handler: "typeerror: cannot read property 'resetfields' of undefined"
Shell脚本——Shell编程规范及变量
Some problems encountered in recent programming 2021 / 9 / 8
ASP. NET CORE3. 1. Solution to login failure after identity registers users
Use of shell awk command
AIOT产业技术全景结构-数字化架构设计(8)
Use between nodejs modules
Shortcut keys (multiline)
Path environment variable
Multithreaded @ async thread pool