Windows Phone 8.1滚动查看器不滚动

时间:2015-06-11 05:16:28

标签: c# .net windows-phone-8 windows-phone-8.1

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

这是我的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>

1 个答案:

答案 0 :(得分:1)

首先:如果网格中只有一行,则可以将其删除,然后插入ScrollViewer。

第二:只需将ScrollViewer的 VerticalAlignment / Horizo​​ntalAlignment 设置为 Stretch 即可。或者在Grid中添加一个Rowdefinition,用于定义ScrollViewer的高度。这是一个适合我的例子:

used