Completed
Last Updated: 23 Feb 2021 10:29 by ADMIN
Release R1 2021 SP2
Massimo
Created on: 22 Feb 2021 10:42
Category: UI Framework
Type: Feature Request
0
RadSvgImage: Add API to clear the cached raster images

When a RadSvgImage document is modified the cache of raster images needs to be cleared, so the modifications can be visualized.
For example we want to change the following SVG

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
	<defs>
		<style>.cls-1{fill:none;stroke:#228bcb;stroke-miterlimit:5;stroke-width:1.2px;} </style>
	</defs>
	<g id="undoModern16">
		<g id="icon">
			<path class="cls-1" d="M5.61,10.36.82,5.51,5.61.63M9.5,14.5h1.28A4.51,4.51,0,0,0,15.38,10h0a4.52,4.52,0,0,0-4.6-4.5H.82" />
		</g>
	</g>
</svg>

 

Here is how it looks :  

To change the color of this SVG we need to change the stroke color of the path that represents the arrow. First, we need to find the element of type SvgPath and then set its stroke to the desired color. 

RadSvgImage svg = this.buttonUndo.SvgImage;
Svg.SvgPath path = svg.Document.Children.FindSvgElementOf<Svg.SvgPath>();
// set arrow color to gray(51,51,51)
path.Stroke = new Svg.SvgColourServer(System.Drawing.Color.FromArgb(51, 51, 51));
// no API to reset the cache

 

As a workaround we need to reassign the image of button:

// clear the cache of RadSvgImage
this.buttonUndo.SvgImage = null;
this.buttonUndo.SvgImage = svg;

Another possible workaround when working with LightVisualElement and its derivatives is to clear the cache with reflection:

var fi = svg.GetType().GetField("cachedSizesToImages", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
     fi.SetValue(svg, new Dictionary<Size, Bitmap>());

0 comments