Windows 8 series-GirdView rolling event acquisition-casual

Source: Internet
Author: User

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 ){}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.