2017-10-02 2 views
0

UWP 앱을 만들려고합니다. 나는 각각 HubSections의 큰 숫자를 갖는 Hub을 가지므로 각 섹션은 하루를 나타냅니다 (오늘은 오늘).HubSections UWP 허브에 바인딩

나는 HubSections의 숫자를 모르지만 모두 같은 콘텐츠 템플릿을 가지고 있습니다.

HubSections 이외의 Hub에는 아무 것도 추가 할 수 없습니다. 그래서 ItemsControl은 옵션이 아닙니다.

동적으로 원하는만큼 많이 만들려면 허브의 HubSections을 어떻게 바인딩 할 수 있습니까?

<Hub ItemsSource={Binding MySectionData}> 
    <DataTemplate> 
    <!-- I would define the HubSection template here --> 
    </DataTemplate> 
</Hub> 

답변

1

어떻게 내가 동적으로 원하는만큼을 만들기 위해 허브의 HubSections을 결합 할 수있다 : 나는 무엇을 달성하고자하는

?

HubSections을 동적으로 만들려면 코드를 생성하기 만하면됩니다. HubSections은 모두 위에서 설명한대로 ContentTemplate을 가지므로 XAML에서 DataTemplate을 정의하고 HubSection을 동적으로 추가 할 때 ContentTemplateHubSection 인 것으로 설정할 수 있습니다.

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를 참조하시기 바랍니다.

관련 문제