简体   繁体   English

C#:Winform / WPF / UWP 中的砌体布局

[英]C#: Masonry Layout in Winform / WPF / UWP

I'm trying to develop a masonry layout in a custom-made image grid/gallery control in WinForm.我正在尝试在 WinForm 中的定制图像网格/画廊控件中开发砌体布局。 Currently my control displays images in a square grid format with fast GDI rendering.目前,我的控件以具有快速 GDI 渲染的方形网格格式显示图像。 Masonry layouts are usually common for web, and there's a lot of resources available on the internet for CSS and Javascript. Masonry 布局通常用于 Web,并且 Internet 上有很多关于 CSS 和 Javascript 的资源。 But I noted that some Windows10 applications are also displaying masonry layout, such as Photos app.但我注意到一些 Windows10 应用程序也显示砖石布局,例如照片应用程序。 Another thing I noted is that the commonly used masonry layout on the web is developed in vertical orientation (variable heights) whereas the layout used by Win10 Photos app (and also other similar apps) are using a fixed row height horizontal masonry layout.我注意到的另一件事是网络上常用的砌体布局是在垂直方向(可变高度)开发的,而 Win10 照片应用程序(以及其他类似应用程序)使用的布局使用固定行高水平砌体布局。

照片应用砌体布局

I'm trying to develop a similar code (as per screenshot of Photos app).我正在尝试开发类似的代码(根据照片应用程序的屏幕截图)。 The point I'm unable to figure out is how the layout configures that how many items to show in each row.我无法弄清楚的一点是布局如何配置每行显示多少项目。 There are rows that have 4 items, 3 items or sometimes 5 items.有些行有 4 个项目、3 个项目或有时 5 个项目。 Its purely flexible depending upon the photo sizes/aspect.它完全灵活,具体取决于照片尺寸/方面。 Overall the width of the layout control/panel is fixed.总体而言,布局控件/面板的宽度是固定的。

Is this type of layout inherently supported by UWP apps? UWP 应用程序本身是否支持这种类型的布局? Does anyone know any links / guides that explain the logic behind this type of layout?有谁知道任何解释这种布局背后逻辑的链接/指南? Does the Photos app has public source code?照片应用程序有公共源代码吗? Another UWP app I've seen implementing this type of layout is the "Perfect Flickr" app.我见过的另一个实现这种布局的 UWP 应用是“Perfect Flickr”应用。

Does anyone know any links / guides that explain the logic behind this type of layout?有谁知道任何解释这种布局背后逻辑的链接/指南?

The UWP Community toolkit has a StaggeredPanel control which is similar to the one you mentioned. UWP 社区工具包有一个StaggeredPanel控件,它类似于您提到的那个控件。 It's open source.它是开源的。 You could check its source code to learn how to arrange its child elements.您可以查看其源代码以了解如何排列其子元素。

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

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