简体   繁体   English

带滚动查看器的图片库 - 环绕面板不考虑滚动查看器的边界

[英]image gallery with scrollviewer - wrap panel does not respect boundaries of scroll viewer

I'm trying to create a gallery-style layout with a ScrollViewer and a WrapPanel in WPF, but the WrapPanel is extending beyond the boundaries of the ScrollViewer.我正在尝试在 WPF 中使用 ScrollViewer 和 WrapPanel 创建画廊式布局,但 WrapPanel 超出了 ScrollViewer 的边界。 I've tried setting the HorizontalAlignment and VerticalAlignment properties of the WrapPanel to "Left" and "Top" respectively, but it still doesn't stay within the boundaries of the ScrollViewer.我已经尝试将 WrapPanel 的 HorizontalAlignment 和 VerticalAlignment 属性分别设置为“Left”和“Top”,但它仍然没有停留在 ScrollViewer 的边界内。

I've also tried setting the height of the WrapPanel to specific values and set the MaxHeight properties of the WrapPanel to limit the size, but it still doesn't stay within the boundaries of the ScrollViewer, and is no longer scrollable.我也试过将 WrapPanel 的高度设置为特定值,并设置 WrapPanel 的 MaxHeight 属性来限制大小,但它仍然没有停留在 ScrollViewer 的边界内,并且不再可滚动。 I've also tried wrapping the WrapPanel inside a Grid and set the height of the Grid to the size I want and set the ClipToBounds property of the Grid as "True", but it still doesn't work.我也试过将 WrapPanel 包裹在 Grid 中,并将 Grid 的高度设置为我想要的大小,并将 Grid 的 ClipToBounds 属性设置为“True”,但它仍然不起作用。

I'm not sure what else I can do to keep the WrapPanel within the boundaries of the ScrollViewer.我不确定我还能做些什么来将 WrapPanel 保持在 ScrollViewer 的边界内。 Can anyone help me figure out how to contain the WrapPanel within the ScrollViewer?谁能帮我弄清楚如何在 ScrollViewer 中包含 WrapPanel?

This is my xaml code:这是我的 xaml 代码:

<ScrollViewer Grid.Row="0">
    <WrapPanel x:Name="Preview_WrapPanel"></WrapPanel>
</ScrollViewer>

and this is my result in my app, in the beginning, the distance from top is correct but the bottom not.这是我在我的应用程序中的结果,一开始,到顶部的距离是正确的,但底部不是。 I scrolled a little up to show that the height is not respected in the top region as well:我向上滚动了一点以显示顶部区域的高度也没有受到尊重: 在此处输入图像描述

the width is respected, but i think only because this is the application width.宽度受到尊重,但我认为只是因为这是应用程序宽度。

The thick red border is the area, which the scrollviewer occupies.粗红色边框是滚动查看器占据的区域。 The wrappanel should be contained inside, kind of like a window, where you can only see whats behind the window and not the trees behind the wall.包裹面板应该包含在里面,有点像 window,在那里你只能看到 window 后面的东西,而看不到墙后面的树。

the wrappanel gets filled with WebView2 Media, each image around 200x200px:包裹面板充满了 WebView2 媒体,每张图片大约 200x200 像素:

WebView2 media = new WebView2();
media.Source = new Uri(nftFile.FullName);
media.Width = 200;
media.Height = 200;
this.Preview_WrapPanel.Children.Add(media);

I use Webview2 because the content could pretty much be anything, image, video, pdf, whatever.我使用 Webview2,因为内容几乎可以是任何东西,图像、视频、pdf 等等。 Also it supports webp For now though, im only adding images.它还支持 webp 不过现在,我只添加图像。

There was a known bug with webview2 and it seems it has not been fixed. webview2 有一个已知错误,似乎尚未修复。

Basically, renders on top so cannot be clipped.基本上,渲染在顶部所以不能被剪裁。

https://github.com/MicrosoftEdge/WebView2Feedback/issues/2579 https://github.com/MicrosoftEdge/WebView2Feedback/issues/2579

https://github.com/MicrosoftEdge/WebView2Feedback/issues/286https://github.com/MicrosoftEdge/WebView2Feedback/issues/286

You need a different plan.你需要一个不同的计划。

Maybe ensure it doesn't matter when they don't clip.也许确保当他们不剪辑时无关紧要。

Maybe use images.也许使用图像。

Or hope it gets fixed soon.或者希望它能尽快修复。

Andy was correct, this is a known issue. Andy 是正确的,这是一个已知问题。 Microsoft knows about it since .net framework Times (>10 years) but refuses to fix the issue so far.微软从 .net 框架时代(>10 年)就知道这个问题,但到目前为止拒绝解决这个问题。

I solved the issue by Installing the Nuget Package CefSharp which uses the chromium engine as well.我通过安装也使用铬引擎的 Nuget Package CefSharp 解决了这个问题。

What a pitty.真可惜。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM