2016-10-17 3 views
0

UWP에서 목록 상자를 가로 및 세로로 늘리고 싶습니다. 몇 가지 WPF 솔루션을 시도했지만 그 중 아무 것도 작동하지 않았습니다. (Stretch line to width of Itemstemplate canvas in itemscontrol)스트레치 ListBox/ItemsControl in UWP

내가 시도하는 것 :

enter image description here

어떻게 UWP에서 목록 상자를 늘릴 수 :

<Page.Content> 
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
     <ListBox VerticalContentAlignment="Stretch" VerticalAlignment="Stretch" Background="Green"> 
      <ListBox.ItemContainerStyle> 
       <Style TargetType="ListBoxItem"> 
        <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter> 
        <Setter Property="VerticalContentAlignment" Value="Stretch"></Setter> 
        <Setter Property="VerticalAlignment" Value="Stretch"></Setter> 
        <Setter Property="HorizontalAlignment" Value="Stretch"></Setter> 
        <Setter Property="Background" Value="AliceBlue" /> 
       </Style> 
      </ListBox.ItemContainerStyle> 
      <ListBox.Template> 
       <ControlTemplate TargetType="ListBox"> 
        <ItemsPresenter Height="252" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/> 
       </ControlTemplate> 
      </ListBox.Template> 
      <ListBox.ItemsPanel> 
       <ItemsPanelTemplate> 
        <StackPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch" /> 
       </ItemsPanelTemplate> 
      </ListBox.ItemsPanel> 
      <ListBoxItem>asdf</ListBoxItem> 
      <ListBoxItem>asdfasdf</ListBoxItem> 
      <ListBoxItem>asdfsdf</ListBoxItem> 
      <ListBoxItem>34</ListBoxItem> 
      <ListBoxItem>as2df</ListBoxItem> 
      <ListBoxItem>asdf</ListBoxItem> 
     </ListBox> 
    </Grid> 
</Page.Content> 

결과는 다음과 같다?

답변

1

귀하는 명시 적으로 Height="252"을 설정했습니다. 이것이 나타나지 않는 이유입니다. 또한 실제 ListBox의 배경을 Green으로 설정했지만 ItemsPanelTemplate에 의해 무시되므로 Green이 표시되지 않습니다.

최종 XAML은 다음과 같아야합니다.

<ListBox VerticalContentAlignment="Stretch" VerticalAlignment="Stretch" Background="Green"> 
    <ListBox.ItemContainerStyle> 
     <Style TargetType="ListBoxItem"> 
      <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter> 
      <Setter Property="VerticalContentAlignment" Value="Stretch"></Setter> 
      <Setter Property="VerticalAlignment" Value="Stretch"></Setter> 
      <Setter Property="HorizontalAlignment" Value="Stretch"></Setter> 
      <Setter Property="Background" Value="AliceBlue" /> 
     </Style> 
    </ListBox.ItemContainerStyle> 
    <ListBoxItem>asdf</ListBoxItem> 
    <ListBoxItem>asdfasdf</ListBoxItem> 
    <ListBoxItem>asdfsdf</ListBoxItem> 
    <ListBoxItem>34</ListBoxItem> 
    <ListBoxItem>as2df</ListBoxItem> 
    <ListBoxItem>asdf</ListBoxItem> 
</ListBox> 

이것은 테스트되지 않았지만 예상대로 작동해야합니다.

+1

HorizontalAlignment 및 VerticalAlignment는 필요하지 않습니다. –