Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use ItemsControl layout control

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how to use the ItemsControl layout control, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

1. Example of ItemsStackPanel

Controls/CollectionControl/ItemsControlDemo/LayoutControl/ItemsStackPanelDemo.xaml

TopLeft

Controls/CollectionControl/ItemsControlDemo/LayoutControl/ItemsStackPanelDemo.xaml.cs

/ * * ItemsStackPanel-Virtualized layout control Default layout control for ListView (inherited from Panel See / Controls/LayoutControl/PanelDemo.xaml) * FirstCacheIndex-the index position of the first item in the cache in all data * FirstVisibleIndex-the index position of the first item in all data displayed on the screen * LastCacheIndex-the index position of the last item in the cache in all data * LastVisibleIndex-the index position of the last item displayed on the screen in all data * CacheLength-the size of data that needs to be cached outside the visible area (in multiples of the number of bars in the visible area) The default value is 4.0 * for example, when 10 pieces of data can be displayed in the visible area and the CacheLength is 4, the size of the data to be cached outside the visible area is 4 * 10 = 40, that is, the size of the whole cached data is 10 + 4 * 10 = 50 * the actual test shows that there may be some deviation, but it is generally accurate * / using System Using System.Collections.Generic;using System.Linq;using System.Xml.Linq;using Windows.UI.Xaml;using Windows.UI.Xaml.Controls;using Windows.UI.Xaml.Controls.Primitives;using Windows.UI.Xaml.Data;using Windows10.Common;namespace Windows10.Controls.CollectionControl.ItemsControlDemo.LayoutControl {public sealed partial class ItemsStackPanelDemo: Page {public CollectionViewSource MyData {get {XElement root = XElement.Load ("SiteMap.xml"); var items = LoadData (root) / / construct data source CollectionViewSource source = new CollectionViewSource (); source.IsSourceGrouped = true; source.Source = items; source.ItemsPath = new PropertyPath ("Items"); return source;}} private ItemsStackPanel _ itemsStackPanel1 = null;private ItemsStackPanel _ itemsStackPanel2 = null;public ItemsStackPanelDemo () {this.InitializeComponent (); this.Loaded + = ItemsStackPanelDemo_Loaded } private void ItemsStackPanelDemo_Loaded (object sender, RoutedEventArgs e) {DispatcherTimer dTimer = new DispatcherTimer (); dTimer.Interval = TimeSpan.Zero; dTimer.Tick + = DTimer_Tick; dTimer.Start (); / / get the ItemsStackPanel control _ itemsStackPanel1 = listView1.ItemsPanelRoot as ItemsStackPanel; _ itemsStackPanel2 = listView2.ItemsPanelRoot as ItemsStackPanel in ListView / / get the ItemsStackPanel control in ListView / / _ itemsStackPanel1 = Helper.GetVisualChild (listView1); / / _ itemsStackPanel2 = Helper.GetVisualChild (listView2);} private void DTimer_Tick (object sender, object e) {lblMsg1.Text = "FirstCacheIndex:" + _ itemsStackPanel1.FirstCacheIndex.ToString (); lblMsg1.Text + = Environment.NewLine; lblMsg1.Text + = "FirstVisibleIndex:" + _ itemsStackPanel1.FirstVisibleIndex.ToString () LblMsg1.Text + = Environment.NewLine; lblMsg1.Text + = "LastCacheIndex:" + _ itemsStackPanel1.LastCacheIndex.ToString (); lblMsg1.Text + = Environment.NewLine; lblMsg1.Text + = "LastVisibleIndex:" + _ itemsStackPanel1.LastVisibleIndex.ToString (); lblMsg1.Text + = Environment.NewLine; lblMsg1.Text + = "CacheLength:" + _ itemsStackPanel1.CacheLength.ToString () } private void cmbGroupHeaderPlacement_SelectionChanged (object sender, SelectionChangedEventArgs e) {_ itemsStackPanel2.GroupHeaderPlacement = (GroupHeaderPlacement) Enum.Parse (typeof (GroupHeaderPlacement), (e.AddedItems [0] as ComboBoxItem) .Content.ToString ());} / / parse xml data private List LoadData (XElement root) {if (root = = null) return null Var items = from n in root.Elements ("node") select new NavigationModel {Title = (string) n.Attribute ("title"), Url = (string) n.Attribute ("url"), Items = LoadData (n)}; return items.ToList () }}}

2. Example of ItemsWrapGrid

Controls/CollectionControl/ItemsControlDemo/LayoutControl/ItemsWrapGridDemo.xaml

TopLeft

Controls/CollectionControl/ItemsControlDemo/LayoutControl/ItemsWrapGridDemo.xaml.cs

/ * * ItemsWrapGrid-Virtualized layout control Default layout control for GridView (inherited from Panel See / Controls/LayoutControl/PanelDemo.xaml) * FirstCacheIndex-the index position of the first item in the cache in all data * FirstVisibleIndex-the index position of the first item in all data displayed on the screen * LastCacheIndex-the index position of the last item in the cache in all data * LastVisibleIndex-the index position of the last item displayed on the screen in all data * CacheLength-the size of data that needs to be cached outside the visible area (in multiples of the number of bars in the visible area) The default value is 4.0 * for example, when 10 pieces of data can be displayed in the visible area and the CacheLength is 4, the size of the data to be cached outside the visible area is 4 * 10 = 40, that is, the size of the whole cached data is 10 + 4 * 10 = 50 * the actual test shows that there may be some deviation, but it is generally accurate * / using System Using System.Collections.Generic;using System.Linq;using System.Xml.Linq;using Windows.UI.Xaml;using Windows.UI.Xaml.Controls;using Windows.UI.Xaml.Controls.Primitives;using Windows.UI.Xaml.Data;using Windows10.Common;namespace Windows10.Controls.CollectionControl.ItemsControlDemo.LayoutControl {public sealed partial class ItemsWrapGridDemo: Page {public CollectionViewSource MyData {get {XElement root = XElement.Load ("SiteMap.xml"); var items = LoadData (root) / / construct data source CollectionViewSource source = new CollectionViewSource (); source.IsSourceGrouped = true; source.Source = items; source.ItemsPath = new PropertyPath ("Items"); return source;}} private ItemsWrapGrid _ itemsWrapGrid1 = null;private ItemsWrapGrid _ itemsWrapGrid2 = null;public ItemsWrapGridDemo () {this.InitializeComponent (); this.Loaded + = ItemsWrapGridDemo_Loaded } private void ItemsWrapGridDemo_Loaded (object sender, RoutedEventArgs e) {DispatcherTimer dTimer = new DispatcherTimer (); dTimer.Interval = TimeSpan.Zero; dTimer.Tick + = DTimer_Tick; dTimer.Start (); / / get the ItemsWrapGrid control _ itemsWrapGrid1 = gridView1.ItemsPanelRoot as ItemsWrapGrid; _ itemsWrapGrid2 = gridView2.ItemsPanelRoot as ItemsWrapGrid in GridView / / get the ItemsWrapGrid control in GridView / / _ itemsWrapGrid1 = Helper.GetVisualChild (gridView1); / / _ itemsWrapGrid2 = Helper.GetVisualChild (gridView2);} private void DTimer_Tick (object sender, object e) {lblMsg1.Text = "FirstCacheIndex:" + _ itemsWrapGrid1.FirstCacheIndex.ToString (); lblMsg1.Text + = Environment.NewLine; lblMsg1.Text + = "FirstVisibleIndex:" + _ itemsWrapGrid1.FirstVisibleIndex.ToString () LblMsg1.Text + = Environment.NewLine; lblMsg1.Text + = "LastCacheIndex:" + _ itemsWrapGrid1.LastCacheIndex.ToString (); lblMsg1.Text + = Environment.NewLine; lblMsg1.Text + = "LastVisibleIndex:" + _ itemsWrapGrid1.LastVisibleIndex.ToString (); lblMsg1.Text + = Environment.NewLine; lblMsg1.Text + = "CacheLength:" + _ itemsWrapGrid1.CacheLength.ToString () } private void cmbGroupHeaderPlacement_SelectionChanged (object sender, SelectionChangedEventArgs e) {_ itemsWrapGrid2.GroupHeaderPlacement = (GroupHeaderPlacement) Enum.Parse (typeof (GroupHeaderPlacement), (e.AddedItems [0] as ComboBoxItem) .Content.ToString ());} / / parse xml data private List LoadData (XElement root) {if (root = = null) return null Var items = from n in root.Elements ("node") select new NavigationModel {Title = (string) n.Attribute ("title"), Url = (string) n.Attribute ("url"), Items = LoadData (n)}; return items.ToList () Thank you for reading this article carefully. I hope the article "how to use ItemsControl layout controls" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and follow the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report