当前位置:网站首页>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 ;
}
}
边栏推荐
- LeetCode Brush Questions Day 11 String Series "58 Last Word Length"
- 【Yugong Series】August 2022 Go Teaching Course 036-Type Assertion
- What are port 80 and port 443?What's the difference?
- Kubernetes集群搭建Zabbix监控平台
- "104 Maximum Depth of Binary Trees" in LeetCode's Day 12 Binary Tree Series
- 【FPGA】设计思路——I2C协议
- 2022-08-10 The sixth group Hiding spring study notes
- A simple JVM tuning, learn to write it on your resume
- Getting Started with Raspberry Pi (5) System Backup
- Build Zabbix Kubernetes cluster monitoring platform
猜你喜欢
机器学习是什么?详解机器学习概念
What should I do if the channel ServerID is incorrect when EasyCVR is connected to a Hikvision Dahua device and selects another cluster server?
LeetCode Brush Questions Day 11 String Series "58 Last Word Length"
What is machine learning?Explain machine learning concepts in detail
Interchangeability Measurements and Techniques - Calculation of Deviations and Tolerances, Drawing of Tolerance Charts, Selection of Fits and Tolerance Classes
【C语言】入门
leetCode刷题14天二叉树系列之《 110 平衡二叉树判断》
How to learn machine learning?machine learning process
The last update time of the tables queried by the two nodes of the rac standby database is inconsistent
console.log alternatives you didn't know about
随机推荐
Interchangeability and Measurement Technology—Surface Roughness Selection and Marking Method
【力扣】22.括号生成
[ADI low-power 2k code] Based on ADuCM4050, ADXL363, TMP75 acceleration, temperature detection and serial port printing, buzzer playing music (lone warrior)
"104 Maximum Depth of Binary Trees" in LeetCode's Day 12 Binary Tree Series
【FPGA】SDRAM
leetCode刷题14天二叉树系列之《 110 平衡二叉树判断》
MYSQLg advanced ------ clustered and non-clustered indexes
校园兼职平台项目反思
App Basic Framework Construction丨Log Management - KLog
leetcode刷题第13天二叉树系列之《98 BST及其验证》
es-head plugin insert query and conditional query (5)
Is there any way for kingbaseES to not read the system view under sys_catalog by default?
【FPGA】abbreviation
EasyCVR接入GB28181设备时,设备接入正常但视频无法播放是什么原因?
What is ensemble learning in machine learning?
STC8H development (15): GPIO drive Ci24R1 wireless module
[FPGA] Design Ideas - I2C Protocol
En-us is an invalid culture error solution when Docker links sqlserver
[C Language] Getting Started
js uses the string as the js execution code