Method ImageUtil.LoadWpfImageElement
Overload
Loads WPF image element from file, resource or string. Supports xaml, png and other image formats supported by WPF.
public static FrameworkElement LoadWpfImageElement(string image)
Parameters
image (string)
Can be:
|
Returns
FrameworkElement
If image is XAML icon name or starts with |
Exceptions
Remarks
image can be an XAML icon name from the Icons tool of LibreAutomate (LA), like "*Pack.Icon color"
. Full format: "[*<library>]*pack.name[ color][ @size][ %margin][;more icons]"
. Here parts enclosed in []
are optional. The color, size and margin parts can be in any order.
- color -
#RRGGBB
or color name (WPF). If 2 colors like"#008000|#00FF00"
, the second color is for high contrast dark theme. If omitted, will use the system color of control text. Also can be like"#008000|"
to use control text only for dark contrast theme, or"|#00FF00"
for vice versa. - size - icon size 1 to 16, like
"*Pack.Icon blue @12"
. Can be used to make the displayed icon smaller or in some cases less blurry. It is the logical width and height of the icon rendered at the center of a box of logical size 16x16. To make icon bigger, instead set properties Width and Height of the returned element; or MTBase.ImageSize for a toolbar or menu. - margin - icon margins inside a box of logical size 16x16. Format:
%left,top,right,bottom,stretch,snap
. All parts are optional. Examples:"*Pack.Icon blue %,,8,8"
,"*Pack.Icon blue %8,8"
,"*Pack.Icon blue %4,,4,,f"
. The stretch part can bef
(fill) orm
(move); default is uniform. The snap part can bep
(setsSnapsToDevicePixels=True
). Can be used either margin or size, not both. - more icons - can be specified multiple icons separated by semicolon, like
"*Pack1.Icon1 color1; *Pack2.Icon2 color2"
. It allows to create multi-color icons (for example a "filled" icon of one color + an "outline" icon of another color) or to add a small overlay icon (eg to indicate disabled state) at a corner (use margin). - library - name of assembly containing the resource. If omitted, uses System.Reflection.Assembly.GetEntryAssembly.
The LA compiler finds icon strings anywhere in code, gets their XAML from the database, and adds the XAML to the assembly as a string resource (see Properties > Resource > Options). This function gets the XAML from resources (ResourceUtil.GetString). If fails, then tries to get XAML from database, and fails if LA isn't running. Uses ScriptEditor.GetIcon.