Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在C中从中心部分数据模板Windows phone 8.1访问网格视图#_C#_Xaml_Windows Phone 8.1_Win Universal App - Fatal编程技术网

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

C# 如何在C中从中心部分数据模板Windows phone 8.1访问网格视图#,c#,xaml,windows-phone-8.1,win-universal-app,C#,Xaml,Windows Phone 8.1,Win Universal App,请告诉我如何评估中心部分数据模板中的网格视图。 在通用应用程序中(Windows Phone 8.1) 下面是xaml <HubSection Header="English Newspapers" x:Name="HubEnglish"> <DataTemplate x:Name="DTEnglish"> <Grid> <Grid.RowDefinitions>

请告诉我如何评估中心部分数据模板中的网格视图。 在通用应用程序中(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>

异常:灾难性故障(来自HRESULT:0x8000FFFF的异常(E_意外))

找到此代码以获取数据模板

    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");
}
静态DependencyObject FindChildByName(DependencyObject from,字符串名)
{
int count=VisualTreeHelper.GetChildrenCount(从);
for(int i=0;i
好吧,这将有助于说明你也得到了什么样的例外。。你不觉得吗?@DJKRAZE我已经更新了这个问题,只有一个例外。请看一看你看了下面的问题了吗?看,还有其他的解决办法吗
    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");
}