LINQPad.Controls.Image.Style is overwritten when a LINQPad.Util.ScaleMode is active

Came across this small issue when I was building up a tiny interface:

If a LINQPad.Util.ScaleMode is used with LINQPad.Controls.Image, any value set to Styles gets dropped when the image actually renders it's dump.

An incredibly minor problem that I did manage to find a workaround for (by manually adjusting the Style property on HtmlElement,) but I figured it might be worth tweaking if you wanted to knock out an easy bug. :)

Cheers and thanks a bunch as always!

Screenshot:
screenshot of behavior

Repro code:

void Main()
{
    string imagePath = @"C:\Windows\System32\ComputerToastIcon.png";

    LINQPad.Controls.Image image0 = new(imagePath, Util.ScaleMode.ResizeTo(50));
    image0.Styles["border"] = "3px red solid";
    image0.Dump("image0 (with scale mode - `Style` property)");

    LINQPad.Controls.Image image1 = new(imagePath);
    image1.Styles["border"] = "3px red solid";
    image1.Dump("image1 (without scale mode)");

    LINQPad.Controls.Image image2 = new(imagePath, Util.ScaleMode.ResizeTo(50));
    string oldStyle = image2.HtmlElement["style"];
    image2.HtmlElement["style"] = $"border: 3px red solid; {oldStyle}";
    image2.Dump("image2 (with scale mode & workaround)");

    string version = typeof(LINQPad.Util).Assembly.GetType("LINQPad.AppVersion").GetField("VersionString").GetValue(null) as string;
    Util.Metatext($"LINQPad v{version}").Dump();
}

Comments

  • There's a few gremlins in there - they should be fixed for the next build. (Note that after the fix, the exact workaround you have won't work - you would need to use HtmlElement.StyleAttribute instead of HtmlElement["style"].)

  • Give it a good thrashing in 8.6.1 and let me know.
    https://www.linqpad.net/linqpad8.aspx#beta

  • cmd
    cmd
    edited August 2024

    Looks like this is doing exactly what you said it would! HtmlElement.StyleAttribute directly overwriting the resize and such makes way more sense to me, especially with how it merges with the changes in the Control.Style property.

    Well done, and thanks as usual for the mindblowingly fast responses!