XAML:
<GridView x:Name="itemGridView" > <GridView.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel Orientation="Horizontal"/> </ItemsPanelTemplate> </GridView.ItemsPanel> <GridView.GroupStyle> <GroupStyle> <GroupStyle.HeaderTemplate> <DataTemplate> <Grid Margin="1,0,0,6"> <Button AutomationProperties.Name="Group Title" Click="Header_Click" Style="{StaticResource TextPrimaryButtonStyle}" > <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding Title}" Margin="3,-7,10,10" Style="{StaticResource GroupHeaderTextStyle}" /> <TextBlock Text="{StaticResource ChevronGlyph}" FontFamily="Segoe UI Symbol" Margin="0,-7,0,10" Style="{StaticResource GroupHeaderTextStyle}"/> </StackPanel> </Button> </Grid> </DataTemplate> </GroupStyle.HeaderTemplate> <GroupStyle.Panel> <ItemsPanelTemplate> <VariableSizedWrapGrid Orientation="Vertical" Margin="0,0,80,0"/> </ItemsPanelTemplate> </GroupStyle.Panel> </GroupStyle> </GridView.GroupStyle> </GridView>
. Cs:
/// <Summary> /// locate the control content control by name /// </summary> /// <typeparam name = "T"> </typeparam> // /<param name = "parent"> </param> // <param name = "name"> </param> // <returns> </returns> public T findVisualChildByName <T> (DependencyObject parent, string name) where T: DependencyObject {for (int I = 0; I <VisualTreeHelper. getChildrenCount (parent); I ++) {var child = VisualTreeHelper. getChild (parent, I); string ControlName = child. getValue (Control. nameProperty) as string; if (controlName = name) {return child as T;} else {T result = FindVisualChildByName <T> (child, name); if (result! = Null) return result;} return null ;}
XAML-. cs:
// Locate the scrollViewer and scrollBar registration value change event in the gridview // The Tip obtains the event and registers it only after the bound data is obtained. Otherwise, the scrollviewer var scrollViewer = this is not obtained. findVisualChildByName <ScrollViewer> (this. itemGridView, "ScrollViewer ");
// Find the Horizontal Rolling axis var scroollBar = this. FindVisualChildByName <ScrollBar> (scrollViewer, "HorizontalScrollBar"); scroollBar. ValueChanged + = scroollBar_ValueChanged;
Private void scroollBar_ValueChanged (object sender, RangeBaseValueChangedEventArgs e) {ScrollBar scrollbar = sender as ScrollBar; // when the scroll bar value is the maximum and if (e. newValue = scrollbar. maximum &&! IsLoading) {// load data LoadData () asynchronously; // set the value offset of the roller to start the valueChanged event scrollbar again. value = e. newValue-1E-8;} if (e. newValue = scrollbar. minimum ){}}