当前位置: 首页 > news >正文

WPF之配方模块

WPF之配方模块

一 UI设计

<!--配方界面--><TabItemHeader="配方"><Grid><Grid.ColumnDefinitions><ColumnDefinitionWidth="2*"/><ColumnDefinitionWidth="6*"/><ColumnDefinitionWidth="2*"/></Grid.ColumnDefinitions><StackPanel Grid.Column="0"><LabelContent="选择配方"></Label><ComboBoxx:Name="cbb_SelectRecipe"></ComboBox></StackPanel><extoolkit:PropertyGridName="propertyGrid_RecipeParams"Background="AliceBlue"Grid.Column="1"></extoolkit:PropertyGrid><StackPanel Grid.Column="2"><ButtonContent="加载配方"Margin="10"Command="{Binding btn_LoadRecipe_Command}"></Button><ButtonContent="新建配方"Margin="10"Command="{Binding btn_CreateRecipe_Command}"></Button><ButtonContent="删除配方"Margin="10"Command="{Binding btn_DeleteRecipe_Command}"></Button><ButtonContent="保存配方"Margin="10"Command="{Binding btn_SaveRecipe_Command}"></Button><ButtonContent="另存为配方"Margin="10"Command="{Binding btn_SaveAsRecipe_Command}"></Button></StackPanel></Grid></TabItem>

二 系统参数设置界面

<LabelContent="切换配方:"Margin="10"/><ComboBoxx:Name="cbb_SelectedRecipe"Text="{Binding AppParameter.RecipeName}"Margin="10"/><Buttonx:Name="btn_ChangeRecipe"Content="切换配方"Command="{Binding ChangeRecipeCommand}"/>

三 新建配方

UI

<mah:MetroWindowx:Class="AOI缺陷检测软件0103.RecipeView"xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"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:AOI缺陷检测软件0103"mc:Ignorable="d"WindowStartupLocation="CenterScreen"Title="配方名称"Height="140"Width="180"><StackPanel><StackPanelOrientation="Horizontal"Margin="10"><LabelContent=" 配方名称:"/><TextBoxx:Name="txt_RecipeName"Width="100"Text="配方1"/></StackPanel><ButtonMargin="10"Content="确认"Click="Button_Click"/></StackPanel></mah:MetroWindow>

后端

usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows;usingSystem.Windows.Controls;usingSystem.Windows.Data;usingSystem.Windows.Documents;usingSystem.Windows.Input;usingSystem.Windows.Media;usingSystem.Windows.Media.Imaging;usingHelper;usingMahApps.Metro.Controls;namespaceAOI缺陷检测软件0103{/// <summary>/// RecipeView.xaml 的交互逻辑/// </summary>publicpartialclassRecipeView:MetroWindow{publicRecipeView(){InitializeComponent();}privatevoidButton_Click(objectsender,RoutedEventArgse){ZWModelzWModel=newZWModel();// 保存XMLXmlSerializerHelper.WriteXML(zWModel,Path.Combine("./Recipes",txt_RecipeName.Text.Trim()+".xml"),typeof(ZWModel));// 更新UIApplication.Current.Dispatcher.BeginInvoke((Action)(()=>{// 1.获取到_mainWindow窗口var_mainWindow=Application.Current.Windows.Cast<Window>().FirstOrDefault(window=>windowisMainWindow)asMainWindow;// 更新配方列表// 清除已有的_mainWindow.cbb_SelectRecipe.Items.Clear();// 清除已有的_mainWindow.cbb_SelectedRecipe.Items.Clear();// 获取所有配方xml文件string[]filePath=Directory.GetFiles("./Recipes");// 显示到主控件上foreach(stringiteminfilePath){// 获取文件名称stringRecipeName=Path.GetFileName(item);// 加到下拉框里_mainWindow.cbb_SelectRecipe.Items.Add(RecipeName);_mainWindow.cbb_SelectedRecipe.Items.Add(RecipeName);}}));// 关闭窗口this.Close();}}}

主界面 新建配方命令

#region新建配方publicRelayCommandbtn_CreateRecipe_Command{get{returnnewRelayCommand(CreateRecipe);}}publicvoidCreateRecipe(){RecipeViewrecipeView=newRecipeView();recipeView.ShowDialog();}#endregion

四 选择配方显示

<StackPanel Grid.Column="0"><LabelContent="选择配方"></Label><ComboBoxx:Name="cbb_SelectRecipe"DropDownClosed="cbb_SelectRecipe_DropDownClsed"></ComboBox></StackPanel>
privatevoidcbb_SelectRecipe_DropDownClsed(objectsender,EventArgse){stringrecipe=cbb_SelectRecipe.Text;ZWModelzWModel=(ZWModel)XmlSerializerHelper.ReadXML(Path.Combine("./Recipes",recipe),typeof(ZWModel));propertyGrid_RecipeParams.SelectedObject=zWModel;}

五 加载配方显示

// 更新配方列表string[]filePath=Directory.GetFiles("./Recipes");foreach(stringiteminfilePath){stringRecipeName=Path.GetFileName(item);cbb_SelectRecipe.Items.Add(RecipeName);cbb_SelectedRecipe.Items.Add(RecipeName);}

五 当前使用配方的显示和保存(已完成)

<ComboBoxx:Name="cbb_SelectedRecipe"Text="{Binding AppParameter.RecipeName}"Margin="10"/>
/// <summary>/// 保存软件参数命令/// </summary>publicRelayCommand<AppParameter>SaveAppParameterCommand{get{returnnewRelayCommand<AppParameter>(appParameter=>SaveAppParameter(appParameter));}}/// <summary>/// 保存软件参数/// </summary>publicvoidSaveAppParameter(AppParameterappParameter){// 保存参数XmlSerializerHelper.WriteXML(appParameter,@".\\AOI外观检测软件参数\\AppParameter.xml",typeof(AppParameter));MessageBox.Show("保存成功!");}

http://www.jsqmd.com/news/188801/

相关文章:

  • 1.14 数据分析价值如何体现?用数据驱动业务增长的3个关键点
  • WPF之调试Halcon引擎
  • AI大模型入门到实战系列完整目录
  • 不容错过的关键!AI应用架构师构建AI伦理治理框架,迈向负责任AI的关键节点
  • Installer Projects的安装
  • 9款AI学术写作工具深度评测:从开题到论文全程高效辅助
  • 1.15 指标异常波动分析实战:日活下跌50%?5步定位问题根源
  • Python爬虫基础入门:requests+BeautifulSoup完整实战教程(新手易懂)
  • 2026年知名的阻氧型铝合金衬塑复合管直销厂家怎么选,PPR铝合金衬塑复合管、铝合金衬PB复合管源头厂家推荐 - 品牌推荐师
  • 【毕业设计】基于机器学习Yolo3教学辅助系统的开发(学生考试监考系统)
  • 【课程设计/毕业设计】基于Yolo3机器学习教学辅助系统的开发(学生考试监考系统)
  • 人工智能交叉学科创新选题:7个技术前沿领域的深度研究与展望
  • 2026年国内好用的铝合金衬塑复合管制造企业推荐排行榜单,阻氧型铝合金衬塑复合管,铝合金衬塑复合管制造企业哪家强 - 品牌推荐师
  • 部分纸笔谜题规则译文
  • 地图数据下载器地图瓦片下载软件
  • 从自然语言处理到计算机视觉:7个AI核心技术的论文选题指南
  • 市场上比较好的阻氧型铝合金衬塑复合管制造商哪家权威,铝合金衬塑复合管、PERT铝合金衬塑复合管直销厂家哪家强 - 品牌推荐师
  • 离线路径规划
  • QOJ #8240. Card Game
  • 2026年国内知名的铝合金衬塑复合管厂家推荐榜单,PERT铝合金衬塑复合管、PPR铝合金衬塑复合管订做厂家推荐 - 品牌推荐师
  • 2026年市场评价高的铝合金衬PB复合管公司推荐,铝合金衬塑复合管、PERT铝合金衬塑复合管公司排行榜 - 品牌推荐师
  • No.1059 基于S7-1200 PLC博图和组态王升降横移立体库7车位3x3 带解释的梯形...
  • 【毕业设计】使用 CNN 进行森林火灾检测机器学习
  • 离线地图开发3D离线地图开发
  • 深度测评 8个一键生成论文工具:本科生毕业论文写作全攻略
  • 二分法
  • 【课程设计/毕业设计】人工智能使用 CNN 进行森林火灾检测
  • 提示工程架构师实战案例:用Prompt生成的动漫表情包,成为了网络热梗!
  • COMSOL三维电弧放电模拟:温度场、流体场及电磁场分布研究
  • 【课程设计/毕业设计】人工智能基于深度学习方法的头盔佩戴检测研究与系统实现