none
监听GridView中控件,修改控件属性 RRS feed

  • 问题

  • 我新建了一个Gridview网格应用程序,没做任何修改,就用系统默认的GridView x:Name="itemGridView" 然后再cpp里面用这个方法,int i = VisualTreeHelper::GetChildrenCount(itemGridView);得到i = 0;

    GroupedItemsPage.xaml:

    <!-- 在大多数视图状态中使用的水平滚动网格-->
            <GridView
                x:Name="itemGridView"
                AutomationProperties.AutomationId="ItemGridView"
                AutomationProperties.Name="Grouped Items"
                Grid.RowSpan="2"
                Padding="116,137,40,46"
                ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
                ItemTemplate="{StaticResource Standard250x250ItemTemplate}"
                SelectionMode="None"
                IsSwipeEnabled="false"
                IsItemClickEnabled="True"
                ItemClick="ItemView_ItemClick">
                <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>

    StandardStyles.xaml:

     <!-- GroupedItemsPage 和 ItemsPage 中显示的适合网格的 250 像素平方的项模板-->
        <DataTemplate x:Key="Standard250x250ItemTemplate">
            <Grid HorizontalAlignment="Left" Width="250" Height="250">
                <Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}">
                    <Image Source="{Binding Image}" Stretch="UniformToFill" AutomationProperties.Name="{Binding Title}"/>
                </Border>
                <StackPanel VerticalAlignment="Bottom" Background="{StaticResource ListViewItemOverlayBackgroundThemeBrush}">
                    <TextBlock Text="{Binding Title}" Foreground="{StaticResource ListViewItemOverlayForegroundThemeBrush}" Style="{StaticResource TitleTextStyle}" Height="60" Margin="15,0,15,0"/>
                    <TextBlock Text="{Binding Subtitle}" Foreground="{StaticResource ListViewItemOverlaySecondaryForegroundThemeBrush}" Style="{StaticResource CaptionTextStyle}" TextWrapping="NoWrap" Margin="15,0,15,10"/>
                </StackPanel>
            </Grid>
        </DataTemplate>

    GroupedItemsPage.xaml.cpp:

    void GroupedItemsPage::LoadState(Object^ navigationParameter, IMap<String^, Object^>^ pageState)
    {
    	// TODO: 创建适用于问题域的合适数据模型以替换示例数据
    	auto sampleDataGroups = Data::SampleDataSource::GetGroups(safe_cast<String^>(navigationParameter));
    	DefaultViewModel->Insert("Groups", sampleDataGroups);
    	int i = VisualTreeHelper::GetChildrenCount(itemGridView);
    }

    Debug 的结果:

    2012年12月13日 7:56

答案

全部回复