当前位置:网站首页>WPF DataGrid 使用数据模板(2)
WPF DataGrid 使用数据模板(2)
2022-08-11 03:59:00 【flysh05】
效果如下:
1. UI XAML设计
<DataGrid x:Name="gdTestPoints" AutoGenerateColumns="False" Margin="5">
<DataGrid.Columns>
<DataGridTextColumn Header="TestPointName" Binding="{Binding TestPointName}" Width="120"/>
<DataGridTextColumn Header="TestStartDate" Binding="{Binding TestDate}" Width="200"/>
</DataGrid.Columns>
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<DockPanel Background="GhostWhite">
<Image DockPanel.Dock="Left" Source="{Binding ImageUrl}" Height="24" Margin="10"/>
<Grid Margin="0 10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="\*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Text="ID:" FontWeight="Bold"/>
<TextBlock Text="{Binding Id}" Grid.Column="1"/>
<TextBlock Text="TestPointName:" FontWeight="Bold" Grid.Row="1"/>
<TextBlock Text="{Binding TestPointName}" Grid.Column="1" Grid.Row="1"/>
<TextBlock Text="TestStartDate:" FontWeight="Bold" Grid.Row="2"/>
<TextBlock Text="{Binding TestDate}" Grid.Column="1" Grid.Row="2"/>
</Grid>
</DockPanel>
</DataTemplate>
</DataGrid.RowDetailsTemplate>
</DataGrid>
2. UI 后台代码
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public class TestPoint
{
public int Id {
get; set; }
public string TestPointName {
get; set; }
public DateTime TestDate {
get; set; }
public string ImageUrl {
get; set; }
}
public MainWindow()
{
InitializeComponent();
List<TestPoint> points = new List<TestPoint>();
//ImageUrl = "http://www.wpf-tutorial.com/images/misc/john\_doe.jpg"
points.Add(new TestPoint() {
Id = 1, TestPointName = "LCD Test", TestDate = new DateTime(2022, 7, 23), ImageUrl = "yes.png" });
points.Add(new TestPoint() {
Id = 2, TestPointName = "Temperateure Test", TestDate = new DateTime(2022, 1, 17) });
points.Add(new TestPoint() {
Id = 3, TestPointName = "Voltage Test", TestDate = new DateTime(2022, 9, 2), ImageUrl = "No.png" });
gdTestPoints.ItemsSource = points ;
}
}
边栏推荐
- 【FPGA】day21-移动平均滤波器
- 这些云自动化测试工具值得拥有
- Is there any way for kingbaseES to not read the system view under sys_catalog by default?
- App Basic Framework Construction丨Log Management - KLog
- js 将字符串作为js执行代码使用
- uni-app - 城市选择索引列表 / 通过 A-Z 排序的城市列表(uview 组件库 IndexList 索引列表)
- leetcode刷题第13天二叉树系列之《98 BST及其验证》
- Multi-merchant mall system function disassembly 26 lectures - platform-side distribution settings
- 多串口RS485工业网关BL110
- 机器学习可以应用在哪些场景?机器学习有什么用?
猜你喜欢
es-head插件插入查询以及条件查询(五)
Echart地图的省级,以及所有地市级下载与使用
【FPGA】day20-I2C读写EEPROM
LeetCode刷题第11天字符串系列之《 58最后一个单词长度》
Interchangeability and Measurement Technology—Surface Roughness Selection and Marking Method
校园兼职平台项目反思
Which one to choose for mobile map development?
Qnet Weak Network Test Tool Operation Guide
"104 Maximum Depth of Binary Trees" in LeetCode's Day 12 Binary Tree Series
Build Zabbix Kubernetes cluster monitoring platform
随机推荐
Roewe imax8ev cube battery security, what blackening and swelling are hidden behind it?
leetCode刷题14天二叉树系列之《 110 平衡二叉树判断》
A simple JVM tuning, learn to write it on your resume
When EasyCVR is connected to the GB28181 device, what is the reason that the device is connected normally but the video cannot be played?
【FPGA】day22-SPI协议回环
【FPGA】名词缩写
QueryDet:级联稀疏query加速高分辨率下的小目标检测
Multi-serial port RS485 industrial gateway BL110
[FPGA] Design Ideas - I2C Protocol
AVH 动手实践 (二) | 在 Arm 虚拟硬件上部署 PP-OCR 模型
【FPGA】abbreviation
The custom of the C language types -- -- -- -- -- - structure
Binary tree related code questions [more complete] C language
Map中的getOrDefualt方法
Pinduoduo store business license related issues
云平台下ESB产品开发步骤说明
Provincial level of Echart maps, as well as all prefecture-level download and use
MySQL数据库存储引擎以及数据库的创建、修改与删除
【愚公系列】2022年08月 Go教学课程 035-接口和继承和转换与空接口
.NET service registration