当前位置:网站首页>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 ;
}
}
边栏推荐
- What is ensemble learning in machine learning?
- 你不知道的 console.log 替代品
- A large horse carries 2 stone of grain, a middle horse carries 1 stone of grain, and two ponies carry one stone of grain. It takes 100 horses to carry 100 stone of grain. How to distribute it?
- Which one to choose for mobile map development?
- 【FPGA】SDRAM
- A brief analysis of whether programmatic futures trading or manual order is better?
- [FPGA] Design Ideas - I2C Protocol
- 使用百度EasyDL实现智能垃圾箱
- MYSQLg advanced ------ return table
- Enter the starting position, the ending position intercepts the linked list
猜你喜欢
随机推荐
MYSQLg高级------聚簇索引和非聚簇索引
Kubernetes集群搭建Zabbix监控平台
rub the heat - do not open
Description of ESB product development steps under cloud platform
【愚公系列】2022年08月 Go教学课程 036-类型断言
How can users overcome emotional issues in programmatic trading?
使用jackson解析json数据详讲
MYSQLg advanced ------ clustered and non-clustered indexes
EasyCVR接入GB28181设备时,设备接入正常但视频无法播放是什么原因?
STC8H development (15): GPIO drive Ci24R1 wireless module
【FPGA】名词缩写
uni-app - city selection index list / city list sorted by A-Z (uview component library IndexList index list)
EasyCVR接入海康大华设备选择其它集群服务器时,通道ServerID错误该如何解决?
uni-app - 城市选择索引列表 / 通过 A-Z 排序的城市列表(uview 组件库 IndexList 索引列表)
机器学习是什么?详解机器学习概念
.NET自定义中间件
Where can machine learning be applied?What is machine learning useful for?
What is Machine Reinforcement Learning?What is the principle?
移动端地图开发选择哪家?
Qnet弱网测试工具操作指南








