简体   繁体   English

网格列表视图中的WinRT Acessing GridView

[英]WinRT Acessing GridView in a Listview in a Grid

I have a Grid with a GridView and a ListView in it. 我有一个带有GridView和ListView的网格。 I would like to change the datatemplate of the GridView while the program is running by using GridView.ItemTemplate, but the problem is I cannot access the name of the GridView. 我想在程序运行时通过使用GridView.ItemTemplate更改GridView的数据模板,但是问题是我无法访问GridView的名称。 The sample of the code: 代码示例:

<Grid>
 ... Some Grid properties, etc
<Text> ...Some Text above to accompany the desciprition of listview
<ListView x:Name = "somethinginthemiddle"
... ListView properties, location in grid, etc.>
...
<Grid>
<GridView x:Name = "IWantToAccessThis"
</GridView>
</ListView>
</Grid>
</Grid> 

Edit: Might worth noting that there may be more than one gridview generated. 编辑:可能值得注意的是,可能会生成多个gridview。 Should I attempt to go through ListView children? 我应该尝试通过ListView子级吗?

This might be helpful. 这可能会有所帮助。

In the xaml file: 在xaml文件中:

<Page.Resources>
    <DataTemplate x:Key="TestTemplate">
        <Grid>
            <Border Background="LightGray" Height="200" Width="200">
                <TextBlock Text="{Binding}" FontSize="48" Foreground="Green"/>
            </Border>
        </Grid>
    </DataTemplate>
</Page.Resources>

<Grid Background="White">
    <TextBlock>Header</TextBlock>
    <ListView x:Name = "somethinginthemiddle">
        <Grid>
            <GridView x:Name = "IWantToAccessThis">
                <GridView.Items>
                    <x:String>One</x:String>
                    <x:String>Two</x:String>
                </GridView.Items>
            </GridView>
        </Grid>
    </ListView>            
</Grid>

In the xaml.cs file: 在xaml.cs文件中:

    public MainPage()
    {
        this.InitializeComponent();
        IWantToAccessThis.ItemTemplate = Resources["TestTemplate"] as DataTemplate;
    }

Here you can see how to get access to IWantToAccessThis and how to set the ItemTemplate on this control. 在这里,您可以看到如何访问IWantToAccessThis以及如何在此控件上设置ItemTemplate

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM