2016-09-11 7 views
0

아래 예제에서 ListView 컨트롤은 부모 컨테이너 RelativePanel의 너비를 인식합니다. 디자이너에서 레이아웃을 볼 때 ListView가 RelativePanel의 전체 너비를 채우는 것이 분명합니다. 그러나 DataTemplate 내부의 RelativePanel이 부모의 너비를 채우도록 요청하더라도 "왼쪽 맞춤"및 "오른쪽 정렬"을 무시합니다. 부모 컨테이너의 크기를 인식 할 수있는 방법을 찾을 수없는 것 같습니다.ListView의 크기 조정을 사용하기 위해 UWP DataTemplate을 얻는 방법은 무엇입니까?

여기에있는 모든 의견을 환영합니다. ListViewItemHorizontalContentAlignment의 값이 Left이기 때문이다

  <RelativePanel RelativePanel.AlignLeftWithPanel="True" 
          RelativePanel.AlignRightWithPanel="True"> 
       <ListView Name="LstOrders" ItemsSource="{x:Bind Vm.OrdersList, Mode=OneWay}" 
          SelectionMode="None" 
          RelativePanel.AlignLeftWithPanel="True" 
          RelativePanel.AlignRightWithPanel="True" 
          Margin="0,5,0,0"> 
        <ListView.ItemTemplate> 
         <DataTemplate x:DataType="genericOrder:OrderThumbnailVm"> 
          <RelativePanel Name="PanelThumbnail" Margin="0,0,20,0"> 
           <RelativePanel Name="PanelOrderDetails" 
               Background="BlueViolet" 
               RelativePanel.AlignLeftWithPanel="True" 
               RelativePanel.AlignRightWithPanel="True"> 
            <TextBlock Text="{x:Bind Name}" Margin="8,0,0,0" VerticalAlignment="Center" 
               Foreground="{x:Bind Deleted, Mode=OneWay, Converter={StaticResource DeletedColor}}" 
               TextWrapping="WrapWholeWords" 
               RelativePanel.AlignLeftWithPanel="True" 
               RelativePanel.LeftOf="BtnDeleteRestore"/> 
            <Button Name="BtnDeleteRestore" 
              Content="{x:Bind DisplayDelete, Mode=OneWay}" 
              Click="{x:Bind DeleteOrder}" 
              RelativePanel.AlignRightWithPanel="True" 
              FontSize="10" 
              Height="20" 
              Padding="0" 
              Visibility="{x:Bind ShowDeleteButton, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}"/> 
           </RelativePanel> 
          </RelativePanel> 
         </DataTemplate> 
        </ListView.ItemTemplate> 
       </ListView> 
      </RelativePanel> 

답변

2

, 우리는 그것을 무시하고 그것을 Stretch 확인해야합니다. ListViewItem styles and templates에서 찾을 수 있습니다. 내가 말했듯이

이 문제를 해결하기 위해, 우리는 다음과 같은 예를 들어, 그 스타일을 재정의해야 :

<ListView> 
     <ListView.ItemContainerStyle> 
      <Style TargetType="ListViewItem"> 
       <Setter Property="HorizontalContentAlignment" Value="Stretch" /> 
      </Style> 
     </ListView.ItemContainerStyle> 
     <ListView.ItemTemplate> 
      <DataTemplate > 
       <RelativePanel> 
        ... 
       </RelativePanel> 
      </DataTemplate> 
     </ListView.ItemTemplate> 
</ListView> 
+0

브릴리언트! 매력처럼 작동합니다! 컨테이너 스타일을 설정하는 것을 제외하고 나는 모든 것에 대해 노력해 왔습니다. –

관련 문제