简体   繁体   English

MAUI有像UWP中的GridView这样的集合控件可以自动移动item的位置吗?

[英]Does MAUI has collection controls like the GridView in UWP that can auto move the position of item?

How UWP's GridView auto performace UWP 的 GridView 如何自动执行

The data source: IEnumerable.数据来源:IEnumerable。

In PC, when the window's width is 1000,the column is 10;在PC中,当窗口宽度为1000时,列数为10;

when the window's width is 500,the column will be 5;当窗口宽度为500时,列为5;

MAUI's CollectionView MAUI 的 CollectionView

CollectionView uses the ItemsLayout property to set the span value, so that the control can display the column to display. CollectionView 使用 ItemsLayout 属性设置跨度值,以便控件可以显示要显示的列。 But when I change the width of the window in PC, the items wouldn't move.但是当我在 PC 中更改窗口的宽度时,项目不会移动。

It seems to be designed for only using in mobile devices.它似乎是专为在移动设备中使用而设计的。 The Windows won't change size. Windows 不会改变大小。

Then I tried to set the span value in code:然后我尝试在代码中设置跨度值:

private void Button_Clicked (object sender , EventArgs e)
{
    var layout = collectionView.ItemsLayout as GridItemsLayout;
    layout.Span += 2;
}

I use the code above to change the volumn value, however, It doesn't work.我使用上面的代码来更改音量值,但是它不起作用。

So, how can CollectionView change the span value?那么,CollectionView如何改变span值呢?

One of the possible ways is to use the Trigger(I guess, I'm new to MAUI).一种可能的方法是使用触发器(我想,我是 MAUI 的新手)。 Then call the control method like "UpdateVisual()" (I guess).然后调用像“UpdateVisual()”这样的控制方法(我猜)。

I am guessing the reason this did not work was that you were changing the Span on runtime which would probably not notify the UI, what you should be doing instead is reinitializing it, something like:我猜这不起作用的原因是您在运行时更改 Span,这可能不会通知 UI,您应该做的是重新初始化它,例如:

collectionView.ItemsLayout = new GridItemsLayout(2, ItemsLayoutOrientation.Vertical);

Hope this helps!希望这可以帮助!

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

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