Skip to content

Conversation

@niels9001
Copy link
Collaborator

@niels9001 niels9001 commented Jan 9, 2026

  • Updating a few default styles
  • Large images would be stretched beyond their parent container width. This PR fixes that and images will now scale accordingly when the image is larger than the actual window / parent size.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the MarkdownTextBlock image handling by replacing fixed Width/Height sizing with a MaxWidth/MaxHeight constraint-based approach, preventing images from being stretched beyond their parent container. It also includes XAML formatting improvements for the theme options pane and updates to sample documentation.

  • Changed image sizing from fixed dimensions to flexible MaxWidth/MaxHeight constraints to prevent stretching
  • Simplified constraint application logic by directly using MaxWidth/MaxHeight instead of complex scaling calculations
  • Reformatted XAML file with consistent indentation and attribute placement

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
MyImage.cs Refactored image sizing logic to use MaxWidth/MaxHeight constraints instead of fixed dimensions, allowing images to scale properly within their containers
ThemeOptionsPane.xaml Applied consistent code formatting with proper indentation and line breaks
MarkdownTextBlockCustomThemeSample.xaml.cs Added documentation about image corner radius feature and included additional sample image

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +153 to +171
// Apply precedent (markdown-specified) dimensions if provided
if (_precedentWidth != 0)
{
double scaleX = hasMaxWidth && actualWidth > _themes.ImageMaxWidth
? _themes.ImageMaxWidth / actualWidth
: 1.0;
double scaleY = hasMaxHeight && actualHeight > _themes.ImageMaxHeight
? _themes.ImageMaxHeight / actualHeight
: 1.0;

// For Uniform stretch, use the smaller scale to maintain aspect ratio
if (_themes.ImageStretch == Stretch.Uniform || _themes.ImageStretch == Stretch.UniformToFill)
{
double uniformScale = Math.Min(scaleX, scaleY);
finalWidth = actualWidth * uniformScale;
finalHeight = actualHeight * uniformScale;
}
else
{
// For other stretch modes, apply constraints independently
finalWidth = actualWidth * scaleX;
finalHeight = actualHeight * scaleY;
}
_image.MaxWidth = _precedentWidth;
}
if (_precedentHeight != 0)
{
_image.MaxHeight = _precedentHeight;
}

_image.Width = finalWidth;
_image.Height = finalHeight;
// Apply theme constraints - these override natural/precedent if smaller
if (_themes.ImageMaxWidth > 0 && _themes.ImageMaxWidth < _image.MaxWidth)
{
_image.MaxWidth = _themes.ImageMaxWidth;
}
if (_themes.ImageMaxHeight > 0 && _themes.ImageMaxHeight < _image.MaxHeight)
{
_image.MaxHeight = _themes.ImageMaxHeight;
}
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constraint logic at lines 153-171 is outside the else block (line 100-151) that handles non-provider images. When an image provider is used (lines 95-99), the natural dimensions are never set on the image (no MaxWidth/MaxHeight initialization). This causes the comparisons at lines 164 and 168 to use default MaxWidth/MaxHeight values (typically double.PositiveInfinity), which means theme constraints will always appear smaller and override precedent dimensions incorrectly. The constraint application code should either be moved inside both branches (provider and non-provider), or the natural dimension initialization should happen in the provider branch as well.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified, Copilot is correct here about the bugs that this presents. I've pushed tests in 4cc9798 which demonstrate a few of the problematic configurations.

It works correctly when shrinking large images, but incorrectly:

  • Enlarges images that are naturally smaller than the constraint
  • Ignores explicit dimensions from markdown syntax

## Images
Images can be styled with max width, max height, and stretch options. Notice how the text flows naturally without any gaps above or below the image:
Images can be styled with max width, max height, corner radius, and stretch options. Notice how the text flows naturally without any gaps above or below the image:
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation mentions that images can be styled with "corner radius" options, but there is no implementation of corner radius for images in the codebase. This is misleading and should be removed unless the feature is actually implemented.

Copilot uses AI. Check for mistakes.
Copy link
Member

@Arlodotexe Arlodotexe Jan 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was confusing at first because, rendered in the UI, it does display a rendered corner radius on one of the images:

Image

While the original image has no corners:

Image

Checking the live visual tree, the corner radius appears to be set on the Image despite having no property for it and seemingly no parent to inherit it from.

Copilot's comment is correct here but missing a large chunk of the story. This comment is identifying a regression, not incorrect documentation.


Commit Range: d70af2486ce5b6

Story:

The image corner radius feature was added in commit d70af24 ("Adding cornerradius to image") which:

  1. Added ImageCornerRadius property to MarkdownThemes.cs
  2. Added a Border wrapper around the Image in MyImage.cs
  3. Applied _border.CornerRadius = _themes.ImageCornerRadius after loading

About 15 minutes later, commit 86ce5b6 ("Making images scale accordingly") refactored the image sizing logic to use MaxWidth/MaxHeight instead of fixed dimensions. However, this commit accidentally reverted all the corner radius changes:

  • Removed the _border field
  • Removed the Border wrapper (back to _container.Child = _image directly)
  • Removed the _border.CornerRadius = _themes.ImageCornerRadius line
  • Removed ImageCornerRadius property from MarkdownThemes.cs

The documentation in the sample file still references corner radius because it was written for the feature that existed in d70af24, but the implementation was lost in the subsequent refactor.

Resolution: Restore the Border wrapper and ImageCornerRadius property while keeping the new MaxWidth/MaxHeight sizing logic from 86ce5b6.


if (hasMaxWidth || hasMaxHeight)
// Apply precedent (markdown-specified) dimensions if provided
if (_precedentWidth != 0)
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Equality checks on floating point values can yield unexpected results.

Copilot uses AI. Check for mistakes.
Copy link
Member

@Arlodotexe Arlodotexe Jan 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are equality checks (!= 0) on floating point values (double). Copilot is technically correct that comparing floats with == or != can be problematic due to precision issues. However, in this specific case it's actually fine because:

  1. _precedentWidth and _precedentHeight are set from parsed integer values (from markdown width/height attributes) or left as the default 0.
  2. They're never the result of floating-point arithmetic that could introduce precision errors
  3. Comparing to exactly 0 (the default) is safe when the value was either never set or set from a whole number

Field declarations:
MyImage.cs#L22-L23

Set from parsed integers (markdown):
MyImage.cs#L40-L47

Set from parsed integers (HTML):
MyImage.cs#L74-L81

The comment is technically valid as a general warning, but it's a false positive in this context. The values are either 0 (default) or parsed integers, so there's no floating-point precision issue.

False positive.

Arlodotexe and others added 2 commits January 9, 2026 19:17
- Tests that theme constraints should not enlarge images smaller than the constraint
- Tests that precedent dimensions from markdown syntax should be respected
- Tests that theme constraints properly limit larger images
- Reveals current bugs where constraints are always applied regardless of context
Copy link
Member

@Arlodotexe Arlodotexe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surfaced a few regressions:

  • This should be fixed in this PR before closing. Failing tests have been pushed to demonstrate the issue.
  • The missing image corner radius bit should be handled in a new PR.

The remaining review comments from Copilot are either trivial and already merged or false positives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants