溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

容器控件StackPanel控件

發(fā)布時間:2020-08-08 18:32:16 來源:網絡 閱讀:465 作者:windows_phone 欄目:開發(fā)技術

 StackPanel控件也是用于布局的,可以使多個子控件按橫向或者縱向排列,并且可以根據自身大  小拉伸子控件。

 StackPanel默認情況下為縱向排列,當Orientation設置為Horizontal時,橫向排列。

 

 StackPanel-堆放容器 將子元素排列成一行(可沿水平或垂直方向)。

 StackPanel的規(guī)則是:根據附加屬性,我要么讓元素橫著排列,要么豎著排列。

 StackPanel 為啟用布局的 Panel 元素之一。在特定情形下,例如,要將一組對象排列在豎直或  水平列表(例如,項的水平或豎直菜單)中,StackPanel 很有用。設置 Orientation 屬性可確  定列表的方向。Orientation 屬性的默認值為 Vertical。

 StackPanel 中內容的 HorizontalAlignmentVerticalAlignment 默認值均為 Stretch。

 

 附上代碼:

  1. <!--LayoutRoot 是包含所有頁面內容的根網格--> 
  2.     <Grid x:Name="LayoutRoot" Background="Transparent"> 
  3.         <StackPanel Orientation="Vertical"> 
  4.             <Button Content="元素1" ></Button> 
  5.             <Button Content="元素2" ></Button> 
  6.             <Button Content="元素3" ></Button> 
  7.         </StackPanel> 
  8.     </Grid> 

 效果為:

 容器控件StackPanel控件

 附上代碼:

  1. <!--LayoutRoot 是包含所有頁面內容的根網格--> 
  2.     <Grid x:Name="LayoutRoot" Background="Transparent"> 
  3.         <StackPanel Orientation="Horizontal"> 
  4.             <Button Content="元素1" ></Button> 
  5.             <Button Content="元素2" ></Button> 
  6.             <Button Content="元素3" ></Button> 
  7.         </StackPanel> 
  8.     </Grid> 

 效果為: 

 容器控件StackPanel控件

 示例二:

  1. <!--LayoutRoot contains the root grid where all other page content is placed--> 
  2.    <Grid x:Name="LayoutRoot" Background="Transparent"> 
  3.        <Grid.RowDefinitions> 
  4.            <RowDefinition Height="Auto"/> 
  5.            <RowDefinition Height="*"/> 
  6.        </Grid.RowDefinitions> 
  7.  
  8.        <!--TitlePanel contains the name of the application and page title--> 
  9.        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> 
  10.            <TextBlock x:Name="ApplicationTitle" Text="STACKPANEL WITH FOUR ELEMENTS" Style="{StaticResource PhoneTextNormalStyle}"/> 
  11.        </StackPanel> 
  12.  
  13.        <!--ContentPanel - place additional content here--> 
  14.        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> 
  15.            <StackPanel Name="stackPanel" Orientation="Vertical"> 
  16.                <TextBlock Text="TextBlock aligned at right bottom" 
  17.                           HorizontalAlignment="Right" 
  18.                           VerticalAlignment="Bottom" /> 
  19.                <Image Name="p_w_picpath2" Source="/PhoneApp2;component/Images/1-12101Q43P9.jpg" /> 
  20.                <Ellipse Stroke="{StaticResource PhoneAccentBrush}" 
  21.                         StrokeThickness="12" /> 
  22.                <TextBlock Text="TextBlock aligned at left top" 
  23.                           HorizontalAlignment="Left" 
  24.                           VerticalAlignment="Top" /> 
  25.            </StackPanel> 
  26.        </Grid> 
  27.    </Grid> 

 效果圖為:

 容器控件StackPanel控件

 

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI