diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render/MarkdownRenderer.Blocks.cs b/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render/MarkdownRenderer.Blocks.cs index d0d1c812a5c..2c21b4e2884 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render/MarkdownRenderer.Blocks.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render/MarkdownRenderer.Blocks.cs @@ -328,6 +328,8 @@ protected override void RenderCode(CodeBlock element, IRenderContext context) LineHeight = FontSize * 1.4 }; + textBlock.PointerWheelChanged += Preventative_PointerWheelChanged; + var paragraph = new Paragraph(); textBlock.Blocks.Add(paragraph); diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render/MarkdownRenderer.Inlines.cs b/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render/MarkdownRenderer.Inlines.cs index 5b262848489..7be6a6d5be5 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render/MarkdownRenderer.Inlines.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render/MarkdownRenderer.Inlines.cs @@ -250,11 +250,29 @@ protected override async void RenderImage(ImageInline element, IRenderContext co return; } - var image = new Image(); - var scrollViewer = new ScrollViewer(); - var viewbox = new Viewbox(); - scrollViewer.Content = viewbox; - viewbox.Child = image; + var image = new Image + { + Source = resolvedImage, + HorizontalAlignment = HorizontalAlignment.Left, + VerticalAlignment = VerticalAlignment.Top, + Stretch = ImageStretch + }; + + var viewbox = new Viewbox + { + Child = image, + StretchDirection = StretchDirection.DownOnly + }; + + viewbox.PointerWheelChanged += Preventative_PointerWheelChanged; + + var scrollViewer = new ScrollViewer + { + Content = viewbox, + VerticalScrollMode = ScrollMode.Disabled, + VerticalScrollBarVisibility = ScrollBarVisibility.Disabled + }; + var imageContainer = new InlineUIContainer() { Child = scrollViewer }; bool ishyperlink = false; @@ -264,14 +282,6 @@ protected override async void RenderImage(ImageInline element, IRenderContext co } LinkRegister.RegisterNewHyperLink(image, element.Url, ishyperlink); - image.Source = resolvedImage; - image.HorizontalAlignment = HorizontalAlignment.Left; - image.VerticalAlignment = VerticalAlignment.Top; - image.Stretch = ImageStretch; - scrollViewer.VerticalScrollMode = ScrollMode.Disabled; - scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled; - viewbox.StretchDirection = StretchDirection.DownOnly; - if (ImageMaxHeight > 0) { viewbox.MaxHeight = ImageMaxHeight; diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render/MarkdownRenderer.Properties.cs b/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render/MarkdownRenderer.Properties.cs index cc47714b1c6..43cd6fcf458 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render/MarkdownRenderer.Properties.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render/MarkdownRenderer.Properties.cs @@ -10,8 +10,11 @@ // THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE. // ****************************************************************** +using System.Reflection; using Windows.Foundation.Metadata; using Windows.UI.Text; +using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media; namespace Microsoft.Toolkit.Uwp.UI.Controls.Markdown.Render @@ -26,6 +29,16 @@ public partial class MarkdownRenderer private static bool TextDecorationsSupported => (bool)(_textDecorationsSupported ?? (_textDecorationsSupported = ApiInformation.IsTypePresent("Windows.UI.Text.TextDecorations"))); + /// + /// Super Hack to retain inertia and passing the Scroll data onto the Parent ScrollViewer. + /// + private static MethodInfo pointerWheelChanged = typeof(ScrollViewer).GetMethod("OnPointerWheelChanged", BindingFlags.NonPublic | BindingFlags.Instance); + + /// + /// Gets or sets the Root Framework Element. + /// + private FrameworkElement RootElement { get; set; } + /// /// Gets the interface that is used to register hyperlinks. /// diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render/MarkdownRenderer.cs b/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render/MarkdownRenderer.cs index 60d3e664901..5763f65dfb9 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render/MarkdownRenderer.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render/MarkdownRenderer.cs @@ -15,6 +15,7 @@ using Microsoft.Toolkit.Parsers.Markdown; using Microsoft.Toolkit.Parsers.Markdown.Inlines; using Microsoft.Toolkit.Parsers.Markdown.Render; +using Microsoft.Toolkit.Uwp.UI.Extensions; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Documents; @@ -50,6 +51,7 @@ public MarkdownRenderer(MarkdownDocument document, ILinkRegister linkRegister, I public UIElement Render() { var stackPanel = new StackPanel(); + RootElement = stackPanel; Render(new UIElementCollectionRenderContext(stackPanel.Children) { Foreground = Foreground }); // Set background and border properties. @@ -207,5 +209,23 @@ private void RemoveSuperscriptRuns(IInlineContainer container, bool insertCaret) } } } + + private void Preventative_PointerWheelChanged(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e) + { + var pointerPoint = e.GetCurrentPoint((UIElement)sender); + + if (pointerPoint.Properties.IsHorizontalMouseWheel) + { + e.Handled = false; + return; + } + + var rootViewer = VisualTree.FindAscendant(RootElement); + if (rootViewer != null) + { + pointerWheelChanged?.Invoke(rootViewer, new object[] { e }); + e.Handled = true; + } + } } } \ No newline at end of file