0

こんにちは、ScrollViewer を使用しようとしていますが、正しく機能していません。ビューの残りの部分を表示するために下にドラッグすると、トップに戻り続けます。

ページのデザインの高さに静的に高さを設定しようとしましたが、それも機能せず、グリッドでラップしようとしました。

ここに私のxamlがあります

<ScrollViewer Height="768">
    <!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">

    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>

    </Grid.RowDefinitions>

    <!--TitlePanel contains the name of the application and page title-->
    <StackPanel x:Name="TitlePanel" Grid.Row="0"  Margin="12,17,0,28">
        <TextBlock x:Name="ApplicationTitle" Text="myApp" Style="{StaticResource PhoneTextNormalStyle}"/>
        <TextBlock x:Name="PageTitle" Text="Menu" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
    </StackPanel>

    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

        <Button Background="{StaticResource PhoneAccentBrush}" Height="221" Width="223"  HorizontalAlignment="Left" Margin="0,15,0,0" Name="rectangle1"  VerticalAlignment="Top" Click="rectangle1_Click">
            <Image Name="image1" Source="/Images/1.png" />

        </Button>
        <Button Background="{StaticResource PhoneAccentBrush}" Height="221" Width="223" Margin="227,15,0,0"  HorizontalAlignment="Left" Name="rectangle2"  VerticalAlignment="Top" Click="rectangle2_Click">
            <Image Name="image2" Source="/Images/2.png" />

        </Button>
        <Button Background="{StaticResource PhoneAccentBrush}" Height="221" Width="223" Margin="0,0,0,138"  HorizontalAlignment="Left" Name="rectangle3"  VerticalAlignment="Bottom" Click="rectangle3_Click">
            <Image Name="image3" Source="/Images/3.png" />

        </Button>
        <Button Background="{StaticResource PhoneAccentBrush}" Height="221" Width="223" Margin="227,0,0,138"  HorizontalAlignment="Left" Name="rectangle4"  VerticalAlignment="Bottom">
            <Image Name="image4" Source="/Images/4.png" />

        </Button>
        <Button Background="{StaticResource PhoneAccentBrush}" Height="221" Width="223" Margin="0,0,0,-89" HorizontalAlignment="Left" Name="rectangle" VerticalAlignment="Bottom" IsTabStop="True">
            <Image Name="image5" Source="/Images/5.png" />
        </Button>
        <TextBlock Foreground="White" Height="59" FontSize="30" HorizontalAlignment="Left" Margin="79,183,0,0" Name="textBlock1" Text="Stop Gap" VerticalAlignment="Top" Width="133" />
            <TextBlock Foreground="White" Height="59" FontSize="30" HorizontalAlignment="Left" Margin="285,183,0,0" Name="textBlock2" Text="Time Lapse" VerticalAlignment="Top" Width="150" />
            <TextBlock Foreground="White" Height="40" FontSize="30" HorizontalAlignment="Left" Margin="96,413,0,0" Name="textBlock3" Text="Projects" VerticalAlignment="Top" Width="116" />
            <TextBlock Foreground="White" Height="50" HorizontalAlignment="Left" FontSize="30" Margin="321,413,0,0" Name="textBlock4" Text="Settings" VerticalAlignment="Top" Width="114" />


        </Grid>
    <ScrollViewer>
    </ScrollViewer>

</Grid>
</ScrollViewer>

助けていただければ幸いです。

4

2 に答える 2

1

現在の実装が機能しない理由は、基本的に定義が Silverlight にすべての Image コントロールと TextBlock コントロールを 1 つのグリッド セルに配置するように指示しているためです。これは、すべてのオブジェクトが、コードで予想されるように互いにスタックするのではなく、配置とスケーリングの基礎としてグリッドを使用することを意味します。

この結果、コントロールが互いに重なり合い、1 つのコントロールだけが表示されているように見えます (グリッド内のいくつかの項目を強制的に「下」に配置しているため、2 つのコントロールが表示される場合があります。セルの下部に配置され、上部に配置された他のコントロールと重なることはありません. これがおそらく、リストの一部のみが ScrollViewer によって表示されているように見える理由です)。

Josemiguel の答えは、適切な解決策の 1 つを説明しています。もう 1 つの (そして私が思うに) より簡単な選択肢は、1 つ以上のStackPanelコントロールを使用することです。これにより、コントロールが指定された向き (垂直がデフォルト) で互いに積み重ねられるようになります。また、StackPanel を相互にスタックおよびネストすることもできます。

MSDN: http://msdn.microsoft.com/en-us/library/system.windows.controls.stackpanel(v=vs.95).aspx - T - MSDN ページの一番下までスクロールして、わかりやすい例を参照してください。いくつかの色付きの長方形を使用したスタックパネルの。

于 2012-04-10T16:08:50.683 に答える
0

それを実現する最善の方法は、WrapPanel のようなある種のコントロールを使用し、空の DataTemplate を作成して、必要なすべての項目を動的に追加することです。ここここに例があります。

于 2012-04-10T13:10:20.793 に答える