wp(2) 網格佈局

設置 SupportedPageOrientation 讓手機支持橫向和縱向翻滾

SupportedPageOrientation="PortraitOrLandscape"

 

首先定義 行 和 列 以及個元素

<Grid x:Name="LayoutRoot" Background="Transparent">         <Grid.RowDefinitions>             <RowDefinition Height="Auto"/>             <RowDefinition Height="*"/>         </Grid.RowDefinitions>         <Grid.ColumnDefinitions>             <ColumnDefinition Width="Auto"/>             <ColumnDefinition Width="*"/>         </Grid.ColumnDefinitions>

        <Image x:Name="Image1" Grid.Row="0" Grid.Column="0" Stretch="Fill" HorizontalAlignment="Center" Source="Img/bdlogo.gif" Height="300" Width="500"/>

        <!--TitlePanel 包含應用程序的名稱和頁標題-->         <StackPanel Grid.Row="1" Grid.Column="0" Name="buttonlist"  HorizontalAlignment="Center">             <Button Content="按鈕1"/>             <Button Content="按鈕2"/>             <Button Content="按鈕3"/>             <Button Content="按鈕4"/>         </StackPanel>            </Grid>

後臺定義 翻滾觸發事件 

public void Orientation_Lode(object sender, OrientationChangedEventArgs e)
        {
            if ((e.Orientation & PageOrientation.Portrait) == (PageOrientation.Portrait))
            {
                Grid.SetRow(buttonlist, 1);
                Grid.SetColumn(buttonlist, 0);
            }
            else
            {
                Grid.SetRow(buttonlist, 0);
                Grid.SetColumn(buttonlist, 1);
            }
        }


在xaml 頁面中調用方法

  OrientationChanged="Orientation_Lode"





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章