Unplanned
Last Updated: 20 May 2025 08:47 by ADMIN
Pascal
Created on: 20 May 2025 05:54
Category: PictureBox
Type: Feature Request
0
RadPictureBox: Add PasteImage event

Add a call to "OnImageLoaded" to "RadPictureBoxelement.PasteImage()" method or create an event like "ImagePasted" ot be able to tract an image change at this point.

For me I solved this via an Harmony patch that adds a call to OnImageLoaded() on PasteImage()  long time ago. Not really elegant, but I'm a noob in patching with Harmony.

Just want to leave it here for anyone that want ot use this solution too or for Telerik to implement a native way to expose an image change via PasteImage.

[HarmonyPatch(typeof(RadPictureBoxElement))]
[HarmonyPatch("PasteImage")]
public class RadPictureBoxElement_PasteImageFixes
{
    private static readonly Dictionary<RadPictureBoxElement, Image> images = [];

    public static void Prefix(object __instance)
    {
        if (__instance is RadPictureBoxElement pb)
        {
            // Remember our image
            images.Remove(pb);
            images.Add(pb, pb.Image);
        }
    }

    public static void Postfix(object __instance)
    {
        if (__instance is RadPictureBoxElement pb && images.TryGetValue(pb, out var image) && pb.Image != image)
        {
            // Remove first to avoid conflicts on error
            images.Remove(pb);

            // Call "OnImageLoaded"
            var method = typeof(RadPictureBoxElement).GetMethod("OnImageLoaded", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            method.Invoke(pb, null);
        }
    }
}

1 comment
ADMIN
Nadya | Tech Support Engineer
Posted on: 20 May 2025 08:47

Hello, Pascal,

Your feedback for a new event in RadPictureBox is greatly appreciated.

I found this a reasonable request to introduce such an event that triggers when an image is pasted in the RadPictureBox. This is why I approved this feature that you logged on our feedback portal. The workaround that you shared using the Harmony library is also appreciated until we introduce the new functionality.

I also awarded Telerik Points as a gesture of gratitude to you.

Regards,
Nadya | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.