-
Notifications
You must be signed in to change notification settings - Fork 79
More markdowntextblock improvements #771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
| // 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; | ||
| } |
Copilot
AI
Jan 9, 2026
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: |
Copilot
AI
Jan 9, 2026
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
While the original image has no corners:
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: d70af24 → 86ce5b6
Story:
The image corner radius feature was added in commit d70af24 ("Adding cornerradius to image") which:
- Added
ImageCornerRadiusproperty toMarkdownThemes.cs - Added a
Borderwrapper around theImageinMyImage.cs - Applied
_border.CornerRadius = _themes.ImageCornerRadiusafter 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
_borderfield - Removed the Border wrapper (back to
_container.Child = _imagedirectly) - Removed the
_border.CornerRadius = _themes.ImageCornerRadiusline - Removed
ImageCornerRadiusproperty fromMarkdownThemes.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.
components/MarkdownTextBlock/samples/MarkdownTextBlockCustomThemeSample.xaml.cs
Show resolved
Hide resolved
components/MarkdownTextBlock/samples/MarkdownTextBlockCustomThemeSample.xaml.cs
Outdated
Show resolved
Hide resolved
|
|
||
| if (hasMaxWidth || hasMaxHeight) | ||
| // Apply precedent (markdown-specified) dimensions if provided | ||
| if (_precedentWidth != 0) |
Copilot
AI
Jan 9, 2026
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
_precedentWidthand_precedentHeightare set from parsed integer values (from markdownwidth/heightattributes) or left as the default0.- They're never the result of floating-point arithmetic that could introduce precision errors
- 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.
Co-authored-by: Copilot <[email protected]>
- 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
There was a problem hiding this 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.
Uh oh!
There was an error while loading. Please reload this page.