Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了在GridView(XAML)组中包装/浮动项目’float:left’在最上面的项目上大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如何编写在GridView(XAML-Win8)组中流动项目的代码,如下图所示?

我目前有一个自定义TemplateSELEctor,为第一个项目选择一个不同的(更大)模板,但是这里指定的流程:

@H_502_4@<GroupStyle.Panel> <ItemsPanelTemplate> <q42:WrapPanel Orientation="Horizontal" Width="440" Margin="0,80,0"/> <!-- also tried VariableSizedWrapGrid --> </ItemsPanelTemplate> </GroupStyle.Panel>

类似地包装项目1到3,但是然后将项目4放置在项目6的位置,而不填写项目4和5.

问题变成;我如何编写类似于css的代码

@H_502_4@.item { display: inline-block; } .item1 { float: left; }

,这将使物品像我想要的那样流动?

解决方法

Andreas HAMMar将我联系到一个有效的解决方案: @H_502_4@using System.Collections.Generic; using Application1.Data; using Windows.Foundation; using WindowS.UI.Xaml; using WindowS.UI.Xaml.Controls; namespace Application1 { public class MyGridView : GridView { int _rowVal; int _colVal; readonly List<Size> _sequence; public MyGridView() { _sequence = new List<Size> { LayoutSizes.PriMaryItem,LayoutSizes.SecondarysmallItem,LayoutSizes.OthersmallItem,// 5 LayoutSizes.OthersmallItem,LayoutSizes.SecondaryTallItem,// 7 LayoutSizes.OthersmallItem,// 9 LayoutSizes.OthersmallItem,// 11 LayoutSizes.SecondarysmallItem,LayoutSizes.OthersmallItem }; } protected override void PrepareContainerForItemOverride(DependencyObject element,object item) { base.PrepareContainerForItemOverride(element,item); var dataItem = item as SampleDataItem; var index = -1; if (dataItem != null) { index = dataItem.Group.Items.IndexOf(dataItem); } if (index >= 0 && index < _sequence.Count) { _colVal = (int) _sequence[index].Width; _rowVal = (int) _sequence[index].Height; } else { _colVal = (int) LayoutSizes.OthersmallItem.Width; _rowVal = (int) LayoutSizes.OthersmallItem.Height; } VariableSizedWrapGrid.SetRowSpan(element as UIElement,_rowVal); VariableSizedWrapGrid.SetcolumnSpan(element as UIElement,_colVal); } } public static class LayoutSizes { public static Size PriMaryItem = new Size(6,2); public static Size SecondarysmallItem = new Size(3,1); public static Size SecondaryTallItem = new Size(2,2); public static Size OthersmallItem = new Size(2,1); } } @H_502_4@<local:MyGridView.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel Orientation="Horizontal"/> </ItemsPanelTemplate> </local:MyGridView.ItemsPanel> <local:MyGridView.GroupStyle> <GroupStyle> <GroupStyle.HeaderTemplate> <DataTemplate> <Grid Margin="1,6"> <Button AutomationProperties.Name="Group title" Content="{Binding titlE}" Click="Header_Click" Style="{Staticresource TextButtonStylE}"/> </Grid> </DataTemplate> </GroupStyle.HeaderTemplate> <GroupStyle.Panel> <ItemsPanelTemplate> <VariableSizedWrapGrid ItemWidth="80" ItemHeight="160" Orientation="Vertical" Margin="0,0" MaximumRowsOrcolumns="3"/> </ItemsPanelTemplate> </GroupStyle.Panel> </GroupStyle> </local:MyGridView.GroupStyle> </local:MyGridView>

大佬总结

以上是大佬教程为你收集整理的在GridView(XAML)组中包装/浮动项目’float:left’在最上面的项目上全部内容,希望文章能够帮你解决在GridView(XAML)组中包装/浮动项目’float:left’在最上面的项目上所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。