简体   繁体   English

如何在C#中从中心部分数据模板Windows Phone 8.1访问网格视图

[英]How to Access Grid View from hub section Data Template Windows phone 8.1 in C#

Please tell me how i can assess the grid view in the hub section data template. 请告诉我如何评估中心部分数据模板中的网格视图。 In universal app ( Windows Phone 8.1 ) Following is the xaml 在通用应用程序(Windows Phone 8.1)中,以下是xaml

   <HubSection Header="English Newspapers" x:Name="HubEnglish">
        <DataTemplate x:Name="DTEnglish">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"></RowDefinition>
                    <RowDefinition Height="*"></RowDefinition>
                </Grid.RowDefinitions>
                <StackPanel Orientation="Vertical">
                    <GridView x:Name="LstEnglishNewspapers">
                        <GridView.ItemTemplate>
                            <DataTemplate>

                                <StackPanel Margin="0,0,0,0" Orientation="Horizontal">

                                    <Image x:Name="txtNewspaperImage" Source="{Binding PicPath}" Height="60" Width="60" VerticalAlignment="Center" Margin="0,0,10,0"/>
                                    <StackPanel Orientation="Vertical">
                                        <TextBlock x:Name="txtNewspaperHeader" TextWrapping="Wrap" Foreground="{StaticResource ApplicationForegroundThemeBrush}" FontSize="14.667" FontWeight="Light" Width="200" VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Segoe UI"/>
                                        <TextBlock x:Name="txtNewsHeader" TextWrapping="Wrap" Foreground="{StaticResource ApplicationForegroundThemeBrush}" FontSize="14.667" FontWeight="Light" Width="200" MaxHeight="20" VerticalAlignment="Center" HorizontalAlignment="Left"/>
                                    </StackPanel>

                                </StackPanel>
                            </DataTemplate>

                        </GridView.ItemTemplate>
                    </GridView>

                </StackPanel>
            </Grid>
        </DataTemplate>

    </HubSection>

I have tried using this code to get the grid but im getting exception. 我已经尝试使用此代码来获取网格,但即时通讯异常。

var grid = VisualTreeHelper.GetChild(HubEnglish.ContentTemplate, 0);

Exception : Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)) 异常:灾难性故障(来自HRESULT的异常:0x8000FFFF(E_UNEXPECTED))

Found this code in order to get the data template 找到此代码以获取数据模板

    static DependencyObject FindChildByName(DependencyObject from, string name)
{
    int count = VisualTreeHelper.GetChildrenCount(from);

    for (int i = 0; i < count; i++)
    {
        var child = VisualTreeHelper.GetChild(from, i);
        if (child is FrameworkElement && ((FrameworkElement)child).Name == name)
            return child;

        var result = FindChildByName(child, name);
        if (result != null)
            return result;
    }

    return null;
}

private TextBlock NoArticlesTextBlock;

private void Page_Loaded(object sender, RoutedEventArgs e)
{
    // Note: No need to start searching from the root (this), we can just start
    // from the relevant HubSection or whatever. Make sure your TextBlock has
    // x:Name="NoArticlesTextBlock" attribute in the XAML.
    NoArticlesTextBlock = (TextBlock)FindChildByName(this, "NoArticlesTextBlock");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在集线器部分数据模板Windows Phone 8.1中访问控件 - How do i access a control within a hub section data template windows phone 8.1 Windows Phone 8.1将数据从数据源绑定到XAML(HUB模板) - Windows phone 8.1 binding data to XAML from datasource (HUB template) 如何在C#Windows Phone 8.1中删除网格中的行 - How to delete a row in a grid in C# windows phone 8.1 获取Windows Phone 8.1 / Windows 8.1的当前可见集线器部分 - Get Currently Visible Hub Section for Windows Phone 8.1 / Windows 8.1 C#如何获取访问令牌Facebook Windows Phone 8.1 - C# How to Get Access Token Facebook windows phone 8.1 使用集线器时如何从CB访问控件-Windows Phone 8.1 - How to get access to controls from CB when using hub - Windows Phone 8.1 在Windows Phone 8.1 C#中保存数据 - Save data in windows phone 8.1 c# LongListSelector C#-如何从分组的数据列表中以字符串形式获取SelectedItem-Windows Phone Silverlight 8.1 - LongListSelector C# - How to get SelectedItem as string from grouped data list - Windows Phone Silverlight 8.1 如何使用C#Windows Phone 8.1从URL读取XML数据 - How to read XML data from a URL by using C# Windows Phone 8.1 Windows Phone 8.1集线器部分更新项目(INotifyPropertyChanged) - Windows Phone 8.1 Hub Section Update Items (INotifyPropertyChanged)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM