wpf触发与模板的使用示例:批量生产工具
批量生产工具

<Window x:Class="WpfM20UpdateFW.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:WpfM20UpdateFW"mc:Ignorable="d"Title="FT_MultiUart Tool V2.7 " Height="600" Width="800" WindowState="Maximized" Closed="Window_Closed" KeyDown="Window_KeyDown" Loaded="Window_Loaded"><Window.Resources><RoutedUICommand x:Key="download" Text="download"/><RoutedUICommand x:Key="download_concel" Text="download_concel"/><RoutedUICommand x:Key="settings" Text="settings"/></Window.Resources><Window.InputBindings><KeyBinding Gesture="Alt+D" Key="D" Command="{StaticResource download}"></KeyBinding><KeyBinding Gesture="Alt+C" Key="C" Command="{StaticResource download_concel}"></KeyBinding><KeyBinding Gesture="Alt+S" Key="S" Command="{StaticResource settings}"></KeyBinding></Window.InputBindings><Window.CommandBindings><CommandBinding Command="{StaticResource download}" CanExecute="Button_Click_Download"></CommandBinding><CommandBinding Command="{StaticResource download_concel}" CanExecute="Button_Click_DownloadCancel"></CommandBinding><CommandBinding Command="{StaticResource settings}" CanExecute="Button_Click_Settings"></CommandBinding></Window.CommandBindings><Grid ShowGridLines="false" MinWidth="20" FocusManager.FocusedElement="{Binding ElementName=download}" Grid.ColumnSpan="4"><Grid.RowDefinitions><RowDefinition Height="30"></RowDefinition><RowDefinition Height="*"></RowDefinition></Grid.RowDefinitions><Grid.ColumnDefinitions><ColumnDefinition Width="0.1*"></ColumnDefinition><ColumnDefinition Width="0.1*"></ColumnDefinition><ColumnDefinition Width="0.1*"></ColumnDefinition><ColumnDefinition Width="0.1*"></ColumnDefinition></Grid.ColumnDefinitions><!--<TextBox Grid.Row="0" Grid.Column="0" x:Name="Path" IsReadOnly="True"/>--><Button Grid.Row="0" Grid.Column="0" FontSize="20" FontWeight="Bold" Margin="5,0,5,0" x:Name="settings" Click="Button_Click_Settings">Settings</Button><Button Grid.Row="0" Grid.Column="3" FontSize="20" FontWeight="Bold" Margin="50,0,5,0" x:Name="download" IsDefault="True" Click="Button_Click_Download" >Start</Button><TextBlock Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" x:Name="textBlockDevice" FontFamily="黑体" FontSize="25" HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding DeviceCount}"/><ListBox x:Name="myListBox" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="4"><ListBox.ItemsPanel><ItemsPanelTemplate><WrapPanel Orientation="Horizontal" IsItemsHost="True"/></ItemsPanelTemplate></ListBox.ItemsPanel><ListBox.ItemTemplate><DataTemplate><StackPanel x:Name="myStackPanel" Orientation="Vertical" Background="AliceBlue" Margin="1 0 0 0" Width="300" Height="{Binding ActualHeight, ElementName=myListBox, Mode=OneWay}"><TextBlock x:Name="myCom" FontFamily="黑体" FontSize="25" HorizontalAlignment="Center" VerticalAlignment="Center"><TextBlock.Text ><MultiBinding StringFormat="{}COM{0,-4}"><Binding Path="Name"/></MultiBinding></TextBlock.Text></TextBlock><DataGrid x:Name="myDataGrid" AutoGenerateColumns="True" MaxHeight="400" ItemsSource="{Binding DataGridCollection}"><DataGrid.RowStyle><Style TargetType="DataGridRow"><Setter Property="Background" Value="White" /><Style.Triggers><!-- 这里是根据条件来设置颜色,假设你想要将满足某个条件的行背景设置为绿色 --><DataTrigger Binding="{Binding Row[状态]}" Value="PASS"><Setter Property="Background" Value="Green" /></DataTrigger><DataTrigger Binding="{Binding Row[状态]}" Value="FAIL"><Setter Property="Background" Value="Red" /></DataTrigger><DataTrigger Binding="{Binding Row[状态]}" Value="SKIP"><Setter Property="Background" Value="Gray" /></DataTrigger></Style.Triggers></Style></DataGrid.RowStyle></DataGrid><TextBlock x:Name="myStatus" Text="{Binding Path=Status}" FontFamily="黑体" FontSize="40" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center"><TextBlock.Style><Style TargetType="TextBlock"><Setter Property="Foreground" Value="White" /><Style.Triggers><!-- 这里是根据条件来设置颜色,假设你想要将满足某个条件的行背景设置为绿色 --><DataTrigger Binding="{Binding Status}" Value="PASS"><Setter Property="Foreground" Value="Green" /></DataTrigger><DataTrigger Binding="{Binding Status}" Value="FAIL"><Setter Property="Foreground" Value="Red" /></DataTrigger><DataTrigger Binding="{Binding Status}" Value="SKIP"><Setter Property="Foreground" Value="Gray" /></DataTrigger><DataTrigger Binding="{Binding Status}" Value="READY"><Setter Property="Foreground" Value="Black" /></DataTrigger></Style.Triggers></Style></TextBlock.Style></TextBlock><TextBox x:Name="myLog" Text="{Binding Path=Log}" MinHeight="100" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" AcceptsReturn="True" IsReadOnly="True" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" /></StackPanel></DataTemplate></ListBox.ItemTemplate></ListBox><!--<ListView x:Name="myListBox" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="4"><ListView.ItemsPanel><ItemsPanelTemplate><WrapPanel Orientation="Horizontal" IsItemsHost="True"/></ItemsPanelTemplate></ListView.ItemsPanel><ListView.ItemTemplate><DataTemplate><StackPanel Orientation="Vertical" Background="AliceBlue" Margin="1 0 0 0" Width="300" Height="{Binding ActualHeight, ElementName=myListBox, Mode=OneWay}"><TextBlock x:Name="textBlock" FontFamily="黑体" FontSize="25" HorizontalAlignment="Center" VerticalAlignment="Center"><TextBlock.Text ><MultiBinding StringFormat="{}COM{0,-4}"><Binding Path="Name"/></MultiBinding></TextBlock.Text></TextBlock><DataGrid Name="myDataGrid" AutoGenerateColumns="True" MaxHeight="500" /><TextBlock Text="{Binding Path=Status}" Foreground="{Binding Path=StatusForeground}" FontFamily="黑体" FontSize="40" HorizontalAlignment="Center" VerticalAlignment="Center"/><TextBox x:Name="logText" MinHeight="100" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" AcceptsReturn="True" IsReadOnly="True" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" /></StackPanel></DataTemplate></ListView.ItemTemplate>--><!-- 添加数据绑定项 --><!--</ListView>--><!--<ListBox DockPanel.Dock="Top" x:Name="myListBoxSP" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Center"><ListBox.ItemTemplate><DataTemplate><Grid><ProgressBar x:Name="Progress"><ProgressBar.Value><Binding Path="ProgressValue"></Binding></ProgressBar.Value><ProgressBar.Foreground><Binding Path="ProgressForeground"></Binding></ProgressBar.Foreground></ProgressBar><TextBlock x:Name="textBlock" FontFamily="黑体" FontSize="25" HorizontalAlignment="Center" VerticalAlignment="Center"><TextBlock.Text ><MultiBinding StringFormat="{}SP COM{0,-4}{1,4}%"><Binding Path="Name"/><Binding Path="Value" ElementName="Progress"/></MultiBinding></TextBlock.Text></TextBlock></Grid></DataTemplate></ListBox.ItemTemplate></ListBox>--></Grid>
</Window>
还是不习惯数据绑定的方式,总是想用getcontrol先获取控件,再对控件进行处理。我注释后,绑定也很方便!!!
private void Window_Loaded(object sender, RoutedEventArgs e)
{DataTable dataTable = new DataTable();dataTable.Columns.Add("序号", typeof(int));dataTable.Columns.Add("测试项", typeof(string));dataTable.Columns.Add("状态", typeof(string));dataTable.Columns.Add("值", typeof(string));for (int j = 1; j <= 40; j++){dataTable.Rows.Add(j, "读SN", j < 10?"PASS":"FAIL","FT123456789");}for (int i = 0; i < bindingList.Count; i++){//TextBlock myCom = (TextBlock)MyAPI.getControl(myListBox, i, "myCom");//DataGrid myDataGrid = (DataGrid)MyAPI.getControl(myListBox, i, "myDataGrid");//if (myDataGrid != null)//{// myDataGrid.ItemsSource = dataTable.DefaultView;//}bindingList[i].DataGridCollection = dataTable.DefaultView;//TextBlock myStatus = (TextBlock)MyAPI.getControl(myListBox, i, "myStatus");//myStatus.Text = "PASS";bool b = true;for (int k = 0; k < dataTable.Rows.Count; k++) {if (dataTable.Rows[k]["状态"].Equals("FAIL")){b = false;}}bindingList[i].Status = b?"PASS":"FAIL";//TextBlock myLog = (TextBlock)MyAPI.getControl(myListBox, i, "myLog");//myLog.Text = "测试完成";bindingList[i].Log = "测试完成";}
}
触发示例:多种状态对应不同颜色
DataTrigger 可以设置多种状态,每种状态对应不同的颜色。你可以为 DataGridRow 设置多个 DataTrigger,根据不同的条件更改行的颜色。假设你有一个 Status 列,不同的状态对应不同的颜色,比如 “Green”、“Yellow”、“Red” 等。
示例:多种状态对应不同颜色
假设 DataTable 中有一个 Status 列,根据 Status 的值来设置不同的背景颜色。
1. 创建 DataTable 并绑定到 DataGrid
// 创建 DataTable
DataTable table = new DataTable();
table.Columns.Add("Name", typeof(string));
table.Columns.Add("Status", typeof(string)); // 状态列,用于改变颜色// 添加示例数据
table.Rows.Add("Item 1", "Green"); // 对应绿色
table.Rows.Add("Item 2", "Yellow"); // 对应黄色
table.Rows.Add("Item 3", "Red"); // 对应红色// 绑定到 DataGrid
myDataGrid.ItemsSource = table.DefaultView;
2. 在 XAML 中定义 DataGrid 的 RowStyle
使用多个 DataTrigger 为不同的状态设置不同的行背景颜色:
<DataGrid x:Name="myDataGrid" AutoGenerateColumns="True"><DataGrid.RowStyle><Style TargetType="DataGridRow"><Setter Property="Background" Value="White" /> <!-- 默认背景色 --><Style.Triggers><!-- 当 Status 为 "Green" 时,将行背景设置为绿色 --><DataTrigger Binding="{Binding Path=Row[Status]}" Value="Green"><Setter Property="Background" Value="LightGreen" /></DataTrigger><!-- 当 Status 为 "Yellow" 时,将行背景设置为黄色 --><DataTrigger Binding="{Binding Path=Row[Status]}" Value="Yellow"><Setter Property="Background" Value="Yellow" /></DataTrigger><!-- 当 Status 为 "Red" 时,将行背景设置为红色 --><DataTrigger Binding="{Binding Path=Row[Status]}" Value="Red"><Setter Property="Background" Value="Salmon" /></DataTrigger><!-- 你可以添加更多状态和对应的颜色 --></Style.Triggers></Style></DataGrid.RowStyle>
</DataGrid>
3. 动态修改 DataTable 行状态
你可以在代码中动态修改 Status 列的值来触发颜色变化:
// 将第一行的状态设置为 "Red",触发行背景变为红色
table.Rows[0]["Status"] = "Red";
解释
Path=Row[Status]:绑定到DataRowView的Row属性中的Status列。- 每个
DataTrigger针对Status列的不同值设置不同的背景颜色。 - 你可以根据需要添加更多的
DataTrigger,为更多的状态设置不同的颜色。
这样,你可以通过修改 DataTable 中的状态值,动态控制 DataGrid 中行的颜色变化。
相关文章:
wpf触发与模板的使用示例:批量生产工具
批量生产工具 <Window x:Class"WpfM20UpdateFW.MainWindow"xmlns"http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x"http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d"http://schemas.microsoft.com/expressio…...
brew install node提示:Error: No such keg: /usr/local/Cellar/node
打开本地文件发现Cellar目录下无法生成 node文件,应该是下载时出现问题,重复下载无法解决问题,只能重新安装brew。 步骤1(安装 brew): /bin/zsh -c “$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/ra…...
记录一下gitlab社区版的安装教程
目录 1.更新系统软件包 2.安装必要的依赖 3.添加GitLab源 3.1对于GitLab Enterprise Edition(EE): 3.2对于GitLab Community Edition(CE): 4.安装GitLab 4.1安装GitLab Enterprise Edition(E…...
20. 如何在MyBatis中处理多表关联查询?常见的实现方式有哪些?
在MyBatis中处理多表关联查询是一项常见的需求,特别是在关系型数据库中存储复杂的实体关系时。MyBatis提供了多种方式来实现多表关联查询,常见的实现方式包括使用<association>和<collection>标签在<resultMap>中进行对象关系映射&…...
【百日算法计划】:每日一题,见证成长(013)
题目 回文链表 给你一个单链表的头节点 head ,请你判断该链表是否为回文链表。如果是,返回 true ;否则,返回 false 。 输入:head [1,2,2,1] 输出:true 思路 找到中间节点反转后半部分链表前后链表顺序比…...
PCL 读取和保存点云
目录 一、概述 1.1原理 1.2实现步骤 二、代码实现 2.1关键函数 2.2完整代码 三、实现效果 PCL点云算法汇总及实战案例汇总的目录地址链接: PCL点云算法与项目实战案例汇总(长期更新) 一、概述 1.1原理 PCL (Point Cloud Library) 是…...
js | TypeError: Cannot read properties of null (reading ‘indexOf’) 【解决】
js | TypeError: Cannot read properties of null (reading ‘indexOf’) 【解决】 描述 概述 在前端开发中,遇到TypeError: Cannot read properties of null (reading indexOf)这类错误并不罕见。这个错误通常表明你试图在一个null值上调用indexOf方法,…...
微信小程序-formData使用
作者:fyupeng 技术专栏:☞ https://github.com/fyupeng 项目地址:☞ https://github.com/fyupeng/distributed-blog-system-api 留给读者 一、介绍 在小程序中使用formdata上传数据,可实现多文件上传 跟浏览器中的FormData对象类…...
潜在语义分析(Latent Semantic Analysis,LSA)—无监督学习方法、非概率模型、判别模型、线性模型、非参数化模型、批量学习
定义 输入: X [ x 11 x 12 ⋯ x 1 n x 21 x 22 ⋯ x 2 n ⋮ ⋮ ⋮ ⋮ x m 1 x m 2 ⋯ x m n ] , 文本集合 D { d 1 , d 2 , ⋯ , d n } , 单词集合 W { ω 1 , ω 2 , ⋯ , ω m } , x i j : 单词 ω i 在文本 d j 中出现的频数或权值 X\left[ \begin{array}{cccc} x_{11} …...
【安全漏洞】MySQL 8.0.33 、CVE-2023-22102
mysql-connector-java:jar:8.0.33已经重新定位到mysql-connector-j:jar:8.0.33 安全漏洞描述 在SBOM扫描过程中,检测到mysql-connector-j:8.0.33存在如下高危安全漏洞: CVE-2023-22102:Oracle MySQL Connectors 8.1.0 版本之前存在安全漏洞&…...
Flutter 响应式框架
一、简介 响应式框架会自动使用户界面适应不同的屏幕大小。创建你的用户界面一次,让它显示完美的像素在移动,平板电脑和桌面! 1.1 问题 支持多种显示尺寸通常意味着要多次重新创建同一布局。在传统的Bootstrap方法下,构建响应式…...
电脑AE特效软件 After Effects软件2017中文版下载安装指南 (Win/Mac)
电脑ae特效软件 After Effects软件2017中文版下载安装win/... 电脑AE特效软件 After Effects软件2017中文版下载安装指南 (Win/Mac) Adobe After Effects 2017 是一款功能强大的视频后期处理软件,广泛应用于影视特效制作、动态图形设计、视觉效果合成等领域。其丰…...
C#中的装箱和拆箱是什么
在 C# 中,装箱(Boxing)和拆箱(Unboxing)是与值类型和引用类型相关的概念,涉及到值类型的数据在托管堆(Heap)上的存储方式。 装箱(Boxing) 装箱是指将值类型…...
在 Debian 12 上安装中文五笔输入法
在 Debian 12 上安装中文五笔输入法,你可以通过以下步骤进行: 更新系统包列表: 打开终端,首先更新你的系统包列表: sudo apt update安装输入法框架: 安装 fcitx5 输入法框架: sudo apt install …...
整流器制造5G智能工厂物联数字孪生平台,推进制造业数字化转型
整流器制造行业作为制造业的重要组成部分,也在积极探索数字化转型的新路径。整流器,作为电力电子领域的关键元件,广泛应用于通信、工业控制、新能源等多个领域,其制造过程的智能化升级不仅关乎产品性能的提升,更是推动…...
算法知识点——常用输入输出数据的方式
如果输入的每组数据的结果不相互干扰的话,就可以在本次操作的时候将该组数据的相关结果进行输出。 1、n组输入输出(n确定) scanf("%d",&n); while(n--) {scanf("%d %d",&a,&b); printf("%d %d\n",a,b);}cin…...
如何构建大数据治理平台,助力企业数据决策
建设背景 (1)什么是数据资产 资产由企业及组织拥有和控制,能够提供增值服务、带来经济利益的重要资源。 资产不但需要管理, 更需要运营。 (2)数据资产运营中的问题 数据资产运营中存在的问题主要包括以下…...
Playwright与Selenium的对比:谁是更适合你的自动化测试工具?
在自动化测试领域,Selenium 一直是行业的标杆工具。它功能强大、支持多浏览器、广泛应用于各类项目中。然而,随着技术的发展,新的工具不断涌现,Playwright 作为其中的佼佼者,以其现代化的设计和强大的特性吸引了越来越…...
Netty 相关问题
传统网络编程存在的问题 传统网络编程存在以下问题: 线程创建开销:在Java中,创建线程需要调用操作系统API,这会消耗资源和时间。内存占用高:线程本身占用内存,创建过多线程会导致内存资源紧张。CPU使用率…...
JAVA中线程池的详解
1.概念 顾名思义,线程池就是管理一系列线程的资源池,其提供了一种限制和管理线程资源的方式。每个线程池还维护一些基本统计信息,例如已完成任务的数量。 这里借用《Java 并发编程的艺术》书中的部分内容来总结一下使用线程池的好处&#x…...
stm32G473的flash模式是单bank还是双bank?
今天突然有人stm32G473的flash模式是单bank还是双bank?由于时间太久,我真忘记了。搜搜发现,还真有人和我一样。见下面的链接:https://shequ.stmicroelectronics.cn/forum.php?modviewthread&tid644563 根据STM32G4系列参考手…...
<6>-MySQL表的增删查改
目录 一,create(创建表) 二,retrieve(查询表) 1,select列 2,where条件 三,update(更新表) 四,delete(删除表…...
江苏艾立泰跨国资源接力:废料变黄金的绿色供应链革命
在华东塑料包装行业面临限塑令深度调整的背景下,江苏艾立泰以一场跨国资源接力的创新实践,重新定义了绿色供应链的边界。 跨国回收网络:废料变黄金的全球棋局 艾立泰在欧洲、东南亚建立再生塑料回收点,将海外废弃包装箱通过标准…...
k8s业务程序联调工具-KtConnect
概述 原理 工具作用是建立了一个从本地到集群的单向VPN,根据VPN原理,打通两个内网必然需要借助一个公共中继节点,ktconnect工具巧妙的利用k8s原生的portforward能力,简化了建立连接的过程,apiserver间接起到了中继节…...
C# 求圆面积的程序(Program to find area of a circle)
给定半径r,求圆的面积。圆的面积应精确到小数点后5位。 例子: 输入:r 5 输出:78.53982 解释:由于面积 PI * r * r 3.14159265358979323846 * 5 * 5 78.53982,因为我们只保留小数点后 5 位数字。 输…...
初学 pytest 记录
安装 pip install pytest用例可以是函数也可以是类中的方法 def test_func():print()class TestAdd: # def __init__(self): 在 pytest 中不可以使用__init__方法 # self.cc 12345 pytest.mark.api def test_str(self):res add(1, 2)assert res 12def test_int(self):r…...
Android第十三次面试总结(四大 组件基础)
Activity生命周期和四大启动模式详解 一、Activity 生命周期 Activity 的生命周期由一系列回调方法组成,用于管理其创建、可见性、焦点和销毁过程。以下是核心方法及其调用时机: onCreate() 调用时机:Activity 首次创建时调用。…...
R语言速释制剂QBD解决方案之三
本文是《Quality by Design for ANDAs: An Example for Immediate-Release Dosage Forms》第一个处方的R语言解决方案。 第一个处方研究评估原料药粒径分布、MCC/Lactose比例、崩解剂用量对制剂CQAs的影响。 第二处方研究用于理解颗粒外加硬脂酸镁和滑石粉对片剂质量和可生产…...
深入浅出深度学习基础:从感知机到全连接神经网络的核心原理与应用
文章目录 前言一、感知机 (Perceptron)1.1 基础介绍1.1.1 感知机是什么?1.1.2 感知机的工作原理 1.2 感知机的简单应用:基本逻辑门1.2.1 逻辑与 (Logic AND)1.2.2 逻辑或 (Logic OR)1.2.3 逻辑与非 (Logic NAND) 1.3 感知机的实现1.3.1 简单实现 (基于阈…...
华为OD机考-机房布局
import java.util.*;public class DemoTest5 {public static void main(String[] args) {Scanner in new Scanner(System.in);// 注意 hasNext 和 hasNextLine 的区别while (in.hasNextLine()) { // 注意 while 处理多个 caseSystem.out.println(solve(in.nextLine()));}}priv…...
