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

wpf问题记录

1 把文件资源 比如图片 批量改成可以复制到bin文件里  属性

  

<ItemGroup><Content Include="Resources\b1.jpg" /><Content Include="Resources\b2.jpg" /><Content Include="Resources\b3.jpg" />
</ItemGroup><ItemGroup><Content Include="Resources\*.jpg"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></Content><Content Include="Resources\*.png"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></Content>
</ItemGroup>

2 使用form的框架类   在高版本里面使用  直接修改.scproj

    <UseWindowsForms>true</UseWindowsForms>

3 你的初始化逻辑不依赖 UI 渲染状态、不访问 ActualWidth/Height、不操作可视化树、不需要等窗口显示出来,那么放在构造函数中是完全没问题,甚至是推荐的

4 tools----生成resx

 // 获取 .exe 所在目录(例如:bin\Debug)string outputDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);// 跳到项目根目录:假设是 ..\..\string projectDirectory = Path.GetFullPath(Path.Combine(outputDirectory, @"..\..\.."));string filePath = Path.Combine(projectDirectory, "AA.resx"); // 推荐 .resx 扩展名string Resourcpath = projectDirectory + "\\Resources";// 4. 获取所有图片文件(支持常见格式)string[] imageFiles = Directory.GetFiles(Resourcpath, "*.*").Where(file => new[] { ".jpg", ".jpeg", ".png", ".bmp", ".gif", ".ico" }.Contains(Path.GetExtension(file).ToLower())).ToArray();if (imageFiles.Length == 0){MessageBox.Show("未在 Images 文件夹中找到图片文件。");return;}if (File.Exists(filePath)){File.Delete(filePath);}//获取图片的resourceResXResourceWriter rw = new ResXResourceWriter(filePath);try{foreach (string imageFile in imageFiles){string fileName = Path.GetFileName(imageFile);           // 带扩展名:b1.jpgstring resourceName = Path.GetFileNameWithoutExtension(imageFile); // 不带扩展名:b1if (!fileName.StartsWith("im"))continue;try{rw.AddResource(resourceName, Image.FromFile(imageFile));}catch (Exception ex){MessageBox.Show($"无法加载图片: {fileName}, 错误: {ex.Message}");}}}finally{rw.Generate();rw.Close();}

http://www.dtcms.com/a/325540.html

相关文章:

  • 重学React(五):脱围机制一
  • 关于JavaScript 性能优化的实战指南
  • React 19 通用 ECharts 组件
  • 【牛客刷题】REAL809 转化
  • GPT-5越狱与零点击AI代理攻击:云与IoT系统面临新型威胁
  • 龙虎榜——20250811
  • HTTPS的应用层协议
  • 数据类型 hash
  • 浏览器CEFSharp+X86+win7 之 测试抖音小店订单抓取(八)
  • 秋天落叶可视化
  • 【BFS 树状数组】P9026 [CCC 2021 S4] Daily Commute|普及+
  • DCA1000使用网线采集数据时的注意事项
  • 用于水T1值和脂肪分数量化的上半身自由呼吸磁共振指纹成像|文献速递-医学影像算法文献分享
  • 【软考中级网络工程师】知识点之 TCP 协议深度剖析
  • JavaEE初阶2.0
  • Linux Web服务器与WordPress部署笔记
  • Linux文件描述符相关知识
  • 一周学会Matplotlib3 Python 数据可视化-绘制直方图(Histogram)
  • Linux-常用命令
  • Windows文件时间修改指南:从手动到自动化
  • 10种经典学习方法的指令化应用
  • 【lucene】文档id docid
  • 在CentOS 7上将PostgreSQL数据库从默认路径迁移到自定义目录
  • Qwen-Image:通义团队新开源超强中文文生图模型(技术报告解读)
  • 【C++】哈希表的实现(unordered_map和unordered_set的底层)
  • 药用植物甾体皂苷生物合成途径研究进展--文献精读158
  • fwrite fread与流定位相关接口
  • CoreShop商城框架开启多租户(1)
  • 下一个排列 的 思路总结
  • OrbStack 入门教程:macOS 上的轻量级容器与虚拟机管理工具