wpf – 如何在XAML中的容器(如dll)中获取特定图标?
发布时间:2020-12-13 22:30:01 所属栏目:Windows 来源:网络整理
导读:我可以在XAML中设置图标容器: Image Source="Shell32.dll.ico" / 但是如何在XAML中设置容器中的图标索引?就像是: Image Source="Shell32.dll,5" / 或者像: Image Source="Shell32.dll" Index="5" / 等等… 解决方法 这就是它的方式:首先是IValueConvert
我可以在XAML中设置图标容器:
<Image Source="Shell32.dll.ico" /> 但是如何在XAML中设置容器中的图标索引?就像是: <Image Source="Shell32.dll,5" /> 或者像: <Image Source="Shell32.dll" Index="5" /> 等等… 解决方法
这就是它的方式:首先是IValueConverter:
using System; using System.Diagnostics; using System.Globalization; using System.Runtime.InteropServices; using System.Windows; using System.Windows.Data; using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Imaging; [ValueConversion(typeof(string),typeof(ImageSource))] public class HabeasIcon : IValueConverter { [DllImport("shell32.dll")] private static extern IntPtr ExtractIcon(IntPtr hInst,string lpszExeFileName,int nIconIndex); public object Convert(object value,Type targetType,object parameter,CultureInfo culture) { string[] fileName = ((string)parameter).Split('|'); if (targetType != typeof(ImageSource)) return Binding.DoNothing; IntPtr hIcon = ExtractIcon(Process.GetCurrentProcess().Handle,fileName[0],int.Parse(fileName[1])); ImageSource ret = Imaging.CreateBitmapSourceFromHIcon(hIcon,Int32Rect.Empty,BitmapSizeOptions.FromEmptyOptions()); return ret; } public object ConvertBack(object value,CultureInfo culture) { throw new NotImplementedException(); } } XAML: <Image Source="{Binding Converter={StaticResource iconExtractor},ConverterParameter=c:WindowsSystem32shell32.dll|72}"/> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- active-directory – 有没有Sysinternals ADInsight的替代品
- 如何在Windows上使用Perl在命令行上处理通配符?
- Win10 开启 Hyper-V 安装 CentOS 7 minimal
- windows-7 – Windows 7 x64 – 无头运行的免费虚拟机主机应
- .net – Windows Server 2008上的最大tcp / ip连接
- wpf – System.Windows.Controls.MenuItem没有图标区域
- windows – 批处理文件似乎被缓存
- 可以在Windows上的putty中使用linux ssh私钥文件吗?
- 蓝牙在2台Windows 7计算机上使用C#进行配对而不进行配对
- Windows – Active Directory环境中的桌面联网打印机管理
推荐文章
站长推荐
- windows-server-2008 – 为什么任务管理器不显示
- 从作为iSCSI目标公开的ZFS池中恢复NTFS数据
- windows – 重用Azure Web角色进行后端处理是一个
- 你如何记录Windows服务器配置?
- Windows Embedded Compact 7上真正的Silverlight
- 从Windows 8 / Server 2012中的Windows资源管理器
- wpf – 未在Windows 8中应用Combobox背景
- .net – MSB90错误MSB3086,与TeamCity
- windows-server-2008 – 如何在MSTSC中禁用声音?
- 如何使WIX MSI始终删除以前的版本?
热点阅读