I have a Grid with a GridView and a ListView in it. 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. 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. Should I attempt to go through ListView children?
This might be helpful.
In the xaml file:
<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:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.