news 2026/4/15 18:25:17

WPF之配方模块

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
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("保存成功!");}

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/14 19:27:26

计算机深度学习毕设实战-使用 CNN 进行森林火灾检测人工智能

博主介绍&#xff1a;✌️码农一枚 &#xff0c;专注于大学生项目实战开发、讲解和毕业&#x1f6a2;文撰写修改等。全栈领域优质创作者&#xff0c;博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java、小程序技术领域和毕业项目实战 ✌️技术范围&#xff1a;&am…

作者头像 李华
网站建设 2026/4/13 18:59:12

深度学习毕设选题推荐:深度学习使用 CNN 进行森林火灾检测机器学习

博主介绍&#xff1a;✌️码农一枚 &#xff0c;专注于大学生项目实战开发、讲解和毕业&#x1f6a2;文撰写修改等。全栈领域优质创作者&#xff0c;博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java、小程序技术领域和毕业项目实战 ✌️技术范围&#xff1a;&am…

作者头像 李华
网站建设 2026/4/13 18:59:10

学术写作AI工具全景测评:覆盖研究全流程的9大优选方案

在学术论文撰写过程中&#xff0c;开题报告与正文的高效完成是研究者常见的难题。传统人工撰写模式虽然灵活性较高&#xff0c;但存在效率瓶颈&#xff0c;而现代人工智能技术能够实现内容的快速生成、重复率控制以及文本逻辑优化。实验数据显示&#xff0c;对9种主流智能写作平…

作者头像 李华
网站建设 2026/4/15 18:23:15

智能化学术创作工具组:9款AI应用开题与论文实战测评

在学术论文撰写过程中&#xff0c;开题报告与正文的高效完成是研究者常见的难题。传统人工撰写模式虽然灵活性较高&#xff0c;但存在效率瓶颈&#xff0c;而现代人工智能技术能够实现内容的快速生成、重复率控制以及文本逻辑优化。实验数据显示&#xff0c;对9种主流智能写作平…

作者头像 李华
网站建设 2026/4/13 21:57:13

学术研究智能帮手:9款AI写作工具功能实测与对比

现代人工智能技术在学术论文撰写中展现出显著优势&#xff0c;通过智能写作平台能够高效完成开题报告与正文内容生成&#xff0c;同时实现重复率控制和文本逻辑优化&#xff0c;经实验评估9种主流平台证实其效能提升作用&#xff0c;但需注意所有AI生成内容必须经过研究者严格人…

作者头像 李华
网站建设 2026/4/13 21:57:11

从开题到终稿:9款智能写作工具横向测评与推荐

研究表明&#xff0c;合理运用人工智能技术可显著优化学术论文撰写流程&#xff0c;尤其在开题报告与正文撰写环节展现出效率优势。通过评估9种主流智能写作平台发现&#xff0c;AI工具在内容快速生成、文本重复率控制及逻辑结构优化方面具有突出表现&#xff0c;能够有效突破传…

作者头像 李华