2016-12-10 16 views
0

我創建UWP應用程序並使用RelativePanel。 我使用相對panel.alignwithright,頂部,左側,底部面板拉伸寬度到列表視圖。 但在將其他元素(例如Stackpanel)添加到列表視圖的右側後,其他面板不會在頁面中查看。 所以我刪除relativePanel.AlignWithRight,在這種情況下不能在列表視圖中拉伸寬度。UWP Xaml相對面板,拉伸和其他元素

我該怎麼辦?

I want this shape to come out.

Now RelativePanel

代碼:

<RelativePanel x:Name="Information" Grid.Row="1"> 
      <ListView x:Name="MyList" 
         RelativePanel.AlignBottomWithPanel="True" 
         RelativePanel.AlignTopWithPanel="True" 
         RelativePanel.AlignRightWithPanel="True" 
         RelativePanel.AlignLeftWithPanel="True"> 
       <ListView.ItemTemplate> 
        <DataTemplate> 
         <userControl:SpendListItem_Template Tapped="SpendListItem_Template_Tapped" ></userControl:SpendListItem_Template> 
        </DataTemplate> 
       </ListView.ItemTemplate> 

       <ListView.ItemContainerStyle> 
        <Style TargetType="ListViewItem"> 
         <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter> 
         <Setter Property="Margin" Value="10,0,10,10"></Setter> 
        </Style> 
       </ListView.ItemContainerStyle> 
      </ListView> 

      <StackPanel x:Name="TotalInformation" RelativePanel.RightOf="MyList" Width="100"> 
       <TextBlock>Test Data</TextBlock> 
      </StackPanel> 
     </RelativePanel> 

回答

1

我敢肯定,你不能只是設置一些RelativePanel附加屬性做純XAML,但你可以處理RelativePanel的SizeChanged事件並以編程方式設置ListView的寬度。這是一個內襯:

private void Information_SizeChanged(object sender, SizeChangedEventArgs e) 
{ 
    MyList.Width = Information.ActualWidth - TotalInformation.ActualWidth; 
} 

<RelativePanel x:Name="Information" Grid.Row="1" SizeChanged="Information_SizeChanged"> 
     <ListView x:Name="MyList"> 
      <ListView.ItemTemplate> 
       <DataTemplate> 
        <userControl:SpendListItem_Template Tapped="SpendListItem_Template_Tapped" ></userControl:SpendListItem_Template> 
       </DataTemplate> 
      </ListView.ItemTemplate> 

      <ListView.ItemContainerStyle> 
       <Style TargetType="ListViewItem"> 
        <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter> 
        <Setter Property="Margin" Value="10,0,10,10"></Setter> 
       </Style> 
      </ListView.ItemContainerStyle> 
     </ListView> 

     <StackPanel x:Name="TotalInformation" RelativePanel.RightOf="MyList" Width="100"> 
      <TextBlock>Test Data</TextBlock> 
     </StackPanel> 
</RelativePanel> 
+0

感謝。它工作得很好。 –

相關問題