wpf - How to get specific icon in a container (like dll) in XAML? -
i can set in xaml icon container:
<image source="shell32.dll.ico" />
but how can set in xaml icon index in container ? like:
<image source="shell32.dll,5" />
or like:
<image source="shell32.dll" index="5" />
etc...
this how goes: first 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, type targettype, object parameter, cultureinfo culture) { throw new notimplementedexception(); } }
the xaml:
<image source="{binding converter={staticresource iconextractor}, converterparameter=c:\\windows\\system32\\shell32.dll|72}"/>
Comments
Post a Comment