어떻게 내가 동적으로 원하는만큼을 만들기 위해 허브의 HubSections을 결합 할 수있다 : 나는 무엇을 달성하고자하는
?
HubSections
을 동적으로 만들려면 코드를 생성하기 만하면됩니다. HubSections
은 모두 위에서 설명한대로 ContentTemplate
을 가지므로 XAML에서 DataTemplate
을 정의하고 HubSection
을 동적으로 추가 할 때 ContentTemplate
이 HubSection
인 것으로 설정할 수 있습니다.
XAML 코드 : 뒤에
<Page.Resources>
<DataTemplate x:Key="FeaturedSectionTemplate">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Style="{StaticResource SubheaderTextBlockStyle}"
Grid.Row="1" Margin="0,10,0,0" TextWrapping="Wrap"
Text="Lorem ipsum dolor sit nonumy sed consectetuer ising elit, sed diam"/>
<TextBlock Style="{StaticResource TitleTextBlockStyle}" Grid.Row="2" Margin="0,10,0,0"
Text="Description text:"/>
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Grid.Row="3"
Text="Lorem ipsum dolor sit amet, consectetuer ising elit... "/>
</Grid>
</DataTemplate>
코드 : 예를 들어
private void Page_Loaded(object sender, RoutedEventArgs e)
{
for (int i = 0; i < 8; i++)
{
HubSection s = new HubSection
{
Name = "name1",
Header = "More...",
//IsHeaderInteractive = true,
Width = 500,
Height = 420,
ContentTemplate = (DataTemplate)this.Resources["FeaturedSectionTemplate"]
};
MyHub.Sections.Add(s);
}
}
자세한 내용은 Using a hub를 참조하시기 바랍니다.