Windows Phone 8.1 Scroll Viewer 無法擺動

本文关键字:Viewer Scroll Phone Windows | 更新日期: 2023-09-27 17:55:19

我在应用程序页面上添加了一个 ScrollViewer 对象,并在 ScrollViewer 对象上添加了许多文本框和组合框,但使用该应用程序的最终用户无法查看所有元素,因为滚动滚动不够低。

这是我的 XAMLCode :

<Page x:Class="mobible.Views.Profile"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="using:mobible.Views"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      mc:Ignorable="d"
      Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
      Height="665">
    <Page.Resources>
        <Style TargetType="ComboBox">
            <Setter Property="Foreground"
                    Value="Black" />
            <Setter Property="Background"
                    Value="White" />
        </Style>
    </Page.Resources>
    <Grid x:Name="LayoutRoot"
          Background="{ThemeResource AppBarItemPointerOverForegroundThemeBrush}"
          AllowDrop="True"
          Height="Auto"
          Width="Auto">
        <ScrollViewer Foreground="#FF0F0D0D"
                      AllowDrop="True"
                      VerticalAlignment="Top"
                      HorizontalAlignment="Center"
                      VerticalScrollBarVisibility="Visible"
                      VerticalScrollMode="Enabled"
                      BringIntoViewOnFocusChange="True"
                      HorizontalScrollMode="Enabled"
                      IsHoldingEnabled="True"
                      Height="715"
                      Margin="0,0,0,-77">
            <StackPanel Height="Auto"
                        Name="stackPanel1"
                        Width="Auto">
                <Grid>
                    <Grid.ChildrenTransitions>
                        <TransitionCollection>
                            <EntranceThemeTransition />
                        </TransitionCollection>
                    </Grid.ChildrenTransitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <!-- Title Panel -->
                    <StackPanel Grid.Row="0"
                                Margin="19,0,0,508"
                                Grid.RowSpan="2">
                        <Image Height="126"
                               Margin="-19,0,-0.167,0"
                               RenderTransformOrigin="0.504,0.025"
                               Source="ms-appx:///Assets/mobible_logo.png"
                               Stretch="Fill"
                               HorizontalAlignment="Right" />
                    </StackPanel>
                    <!--TODO: Content should be placed within the following grid-->
                    <Grid Grid.Row="1"
                          x:Name="ContentRoot"
                          Margin="19,9.5,19,0"
                          HorizontalAlignment="Center">
                        <TextBox x:Name="txt_lastName"
                                 HorizontalAlignment="Left"
                                 Margin="0,238,0,0"
                                 TextWrapping="Wrap"
                                 Text=""
                                 VerticalAlignment="Top"
                                 Width="361"
                                 Background="White"
                                 BorderBrush="#FF0F0D0D" />
                        <Button x:Name="btn_save"
                                Content="Save"
                                HorizontalAlignment="Left"
                                Margin="-2,628,0,0"
                                VerticalAlignment="Top"
                                Width="360"
                                Height="53"
                                Foreground="#FF0F0D0D"
                                Background="#FFEEDA11"
                                FontSize="17" />
                        <TextBox x:Name="txt_dateofbirth"
                                 HorizontalAlignment="Left"
                                 Margin="1,321,0,0"
                                 TextWrapping="Wrap"
                                 Text=""
                                 VerticalAlignment="Top"
                                 Width="361"
                                 Background="White"
                                 BorderBrush="#FF0F0D0D" />
                        <TextBlock HorizontalAlignment="Left"
                                   Margin="2,128,0,0"
                                   TextWrapping="Wrap"
                                   Text="First Name"
                                   VerticalAlignment="Top"
                                   Height="24"
                                   Width="332"
                                   FontSize="18"
                                   Foreground="#FF0E0D0D"
                                   RenderTransformOrigin="0.516,1.217" />
                        <TextBlock HorizontalAlignment="Left"
                                   Margin="3,213,0,0"
                                   TextWrapping="Wrap"
                                   Text="Last Name"
                                   VerticalAlignment="Top"
                                   Height="22"
                                   Width="200"
                                   FontSize="18"
                                   Foreground="#FF0E0D0D"
                                   RenderTransformOrigin="0.516,1.217" />
                        <TextBlock HorizontalAlignment="Left"
                                   Margin="3,292,0,0"
                                   TextWrapping="Wrap"
                                   Text="Date of birth"
                                   VerticalAlignment="Top"
                                   Height="31"
                                   Width="142"
                                   FontSize="18"
                                   Foreground="#FF0E0D0D"
                                   RenderTransformOrigin="0.516,1.217" />
                        <TextBlock HorizontalAlignment="Left"
                                   Margin="1,372,0,0"
                                   TextWrapping="Wrap"
                                   Text="Gender"
                                   VerticalAlignment="Top"
                                   Height="31"
                                   Width="347"
                                   FontSize="18"
                                   Foreground="#FF0E0D0D"
                                   RenderTransformOrigin="0.516,1.217" />
                        <TextBlock HorizontalAlignment="Left"
                                   Margin="3,456,0,0"
                                   TextWrapping="Wrap"
                                   Text="Country"
                                   VerticalAlignment="Top"
                                   Height="31"
                                   Width="347"
                                   FontSize="18"
                                   Foreground="#FF0E0D0D"
                                   RenderTransformOrigin="0.516,1.217" />
                        <TextBox x:Name="txt_firstName"
                                 HorizontalAlignment="Left"
                                 Margin="-2,157,0,0"
                                 TextWrapping="Wrap"
                                 Text=""
                                 VerticalAlignment="Top"
                                 Width="361"
                                 Background="White"
                                 BorderBrush="#FF0F0D0D" />
                        <TextBlock HorizontalAlignment="Left"
                                   Margin="2,540,0,0"
                                   TextWrapping="Wrap"
                                   Text="Religious background"
                                   VerticalAlignment="Top"
                                   Height="31"
                                   Width="347"
                                   FontSize="18"
                                   Foreground="#FF0E0D0D"
                                   RenderTransformOrigin="0.516,1.217" />
                        <ComboBox x:Name="cmbCountry"
                                  ItemsSource="{Binding}"
                                  HorizontalAlignment="Left"
                                  Height="71"
                                  Margin="1,478,0,0"
                                  VerticalAlignment="Top"
                                  Width="361"
                                  Background="White"
                                  Foreground="Black"
                                  BorderBrush="#FF0F0D0D" />
                        <ComboBox x:Name="cmbReligion"
                                  ItemsSource="{Binding}"
                                  HorizontalAlignment="Left"
                                  Height="71"
                                  Margin="1,564,0,0"
                                  VerticalAlignment="Top"
                                  Width="361"
                                  Background="White"
                                  Foreground="Black"
                                  BorderBrush="#FF0F0D0D">
                            <TextBlock />
                        </ComboBox>
                        <ComboBox x:Name="cmbGender"
                                  ItemsSource="{Binding}"
                                  HorizontalAlignment="Left"
                                  Height="148"
                                  Margin="1,401,0,0"
                                  VerticalAlignment="Top"
                                  Width="361"
                                  Background="White"
                                  BorderBrush="#FF0F0D0D" />
                    </Grid>
                </Grid>
            </StackPanel>
        </ScrollViewer>
    </Grid>
</Page>

Windows Phone 8.1 Scroll Viewer 無法擺動

首先:当您的网格中只有一行时,您可以将其删除并插入 ScrollViewer。

第二:只需将滚动查看器的垂直对齐/水平对齐设置为拉伸。或者在网格中添加一个行定义,用于定义滚动查看器的高度。这是一个对我有用的示例:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <ScrollViewer Grid.Row="0">
        <StackPanel>
        .... my elements ...
        </StackPanel>
    </ScrollViewer>
    <Button Grid.Row="1" Content="MyButton" />
</Grid>