我试图在FlowListView
中每行放置三个二次帧。
FlowListView
代码:
<toolkit:FlowListView
FlowColumnCount="3"
HasUnevenRows="True"
FlowRowBackgroundColor="{Binding WidgetMainColor}"
Margin="10,0,10,0"
FlowItemsSource="{Binding TestContainer.WidgetsInContainer}">
<toolkit:FlowListView.FlowColumnTemplate>
<DataTemplate>
<Frame
Margin="5"
WidthRequest="{Binding WidthAndHeightForDashboard}"
HeightRequest="{Binding WidthAndHeightForDashboard}"
BackgroundColor="{Binding WidgetMainColor}"
CornerRadius="2"
HasShadow="False"/>
</DataTemplate>
</toolkit:FlowListView.FlowColumnTemplate>
</toolkit:FlowListView>
WidthAndHeightForDashboard
:
public double WidthAndHeightForDashboard
{
get
{
// -50 for Margin (6 * 5 for Frame margins, 2 * 10 for FlowListView margin)
// rest is divided by 3 because we need 3 frames
return (double)(App.ScreenWidth - 50) / 3;
}
}
我正在使用ScreenWidth
来计算WidthAndHeightForDashboard
因为我知道页面将始终处于纵向模式。这意味着我们将在此页面上拥有更多高度而不是宽度,因此宽度对于二次帧是决定性的。
ScreenWidth
计算方式如下:
App.ScreenWidth = (int)(Resources.DisplayMetrics.WidthPixels / Resources.DisplayMetrics.Density);
正如您在屏幕截图中看到的那样,帧高于宽度,但它们应该是二次的:
我还尝试删除所有边距并从计算中删除边距,以防我的计算出错,但这不能解决问题。
WidthRequest
和HeightRequest
使用的是相同的值但帧数比它们的宽度要高,所以我很确定WidthAndHeightForDashboard
的计算值高于它应该的值...或者屏幕上App.ScreenWidth
所声明的空间可能更少?