I want to create a Hub in XAML that contains a Grid of my construction
I then want to use code behind to set the values
Mikael Koskinen created a great blog entry (http://mikaelkoskinen.net/winrt-xaml-hub-control-getting-started-tutorial-semanticzoom)
The below sample is 100% his (thanks for the blog) - my question is - is there a better way?
<HubSection Header="Trailers">
<DataTemplate>
<ListView x:Name="MovieTrailers">
</ListView>
</DataTemplate>
</HubSection>
Even though we’ve given the ListView a name, we cannot access it from the code-behind:
This is because the control is inside a DataTemplate. One easy way to get around this limitation is to hook into the ListView’s Loaded-event. Here’s the XAML:
<ListView x:Name="MovieTrailers" Loaded="MovieTrailers_Loaded">
</ListView>
And the code behind:
private void MovieTrailers_Loaded(object sender, RoutedEventArgs e)
{
var listView = (ListView)sender;
listView.ItemsSource = trailers;
}