C# 如何在xaml中将scrollview添加到网格
将滚动视图添加到下面的网格是可行的,但是底部的矩形不完全可见,我想将滚动视图添加到内容面板网格中,这样我就可以查看所有的矩形,即使它超过10个C# 如何在xaml中将scrollview添加到网格,c#,xaml,visual-studio-2012,windows-phone-8,C#,Xaml,Visual Studio 2012,Windows Phone 8,将滚动视图添加到下面的网格是可行的,但是底部的矩形不完全可见,我想将滚动视图添加到内容面板网格中,这样我就可以查看所有的矩形,即使它超过10个 <Grid x:Name="LayoutRoot" Background="White" Margin="0,0,0,-45"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Heig
<Grid x:Name="LayoutRoot" Background="White" Margin="0,0,0,-45">
<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">
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ScrollViewer >
<Grid>
<Rectangle Fill="#FF283742" HorizontalAlignment="Left" Height="184" Margin="10,0,0,0" Stroke="Black" VerticalAlignment="Top" Width="436"/>
<Rectangle Fill="#FF876D6D" HorizontalAlignment="Left" Height="130" Margin="10,192,0,0" Stroke="Black" VerticalAlignment="Top" Width="217"/>
<Rectangle Fill="#FF565D41" HorizontalAlignment="Left" Height="133" Margin="237,189,0,0" Stroke="Black" VerticalAlignment="Top" Width="209"/>
<Rectangle Fill="#FF322929" HorizontalAlignment="Left" Height="205" Margin="10,327,0,0" Stroke="Black" VerticalAlignment="Top" Width="436"/>
<Rectangle Fill="#FF2F5151" HorizontalAlignment="Left" Height="98" Margin="10,537,0,0" Stroke="Black" VerticalAlignment="Top" Width="217"/>
<Rectangle Fill="#FF1E7870" HorizontalAlignment="Left" Height="108" Margin="237,537,0,0" Stroke="Black" VerticalAlignment="Top" Width="209"/>
</Grid>
</ScrollViewer>
</Grid>
</Grid>
您需要在Scrollviewer中明确设置网格的高度,或者更改Stackpanel的网格并调整矩形。您需要在Scrollviewer中明确设置网格的高度,或者更改Stackpanel的网格并调整矩形。您需要在Scrollviewer或更改Stackpanel的网格并调整矩形。您需要在Scrollviewer中明确设置网格的高度,或更改Stackpanel的网格并调整矩形。将网格替换为Stackpanel并定位矩形
<ScrollViewer Height="400" VerticalScrollBarVisibility="Auto" >
<StackPanel VerticalAlignment="Top" >
<Rectangle Fill="#FF283742" HorizontalAlignment="Left" Height="184" Margin="10,0,0,0" Stroke="Black" VerticalAlignment="Top" Width="436"/>
<Rectangle Fill="#FF876D6D" HorizontalAlignment="Left" Height="130" Margin="10,192,0,0" Stroke="Black" VerticalAlignment="Top" Width="217"/>
<Rectangle Fill="#FF565D41" HorizontalAlignment="Left" Height="133" Margin="237,189,0,0" Stroke="Black" VerticalAlignment="Top" Width="209"/>
<Rectangle Fill="#FF322929" HorizontalAlignment="Left" Height="205" Margin="10,327,0,0" Stroke="Black" VerticalAlignment="Top" Width="436"/>
<Rectangle Fill="#FF2F5151" HorizontalAlignment="Left" Height="98" Margin="10,537,0,0" Stroke="Black" VerticalAlignment="Top" Width="217"/>
<Rectangle Fill="#FF1E7870" HorizontalAlignment="Left" Height="108" Margin="237,537,0,0" Stroke="Black" VerticalAlignment="Top" Width="209"/>
</StackPanel>
</ScrollViewer>
用StackPanel替换网格并定位矩形
<ScrollViewer Height="400" VerticalScrollBarVisibility="Auto" >
<StackPanel VerticalAlignment="Top" >
<Rectangle Fill="#FF283742" HorizontalAlignment="Left" Height="184" Margin="10,0,0,0" Stroke="Black" VerticalAlignment="Top" Width="436"/>
<Rectangle Fill="#FF876D6D" HorizontalAlignment="Left" Height="130" Margin="10,192,0,0" Stroke="Black" VerticalAlignment="Top" Width="217"/>
<Rectangle Fill="#FF565D41" HorizontalAlignment="Left" Height="133" Margin="237,189,0,0" Stroke="Black" VerticalAlignment="Top" Width="209"/>
<Rectangle Fill="#FF322929" HorizontalAlignment="Left" Height="205" Margin="10,327,0,0" Stroke="Black" VerticalAlignment="Top" Width="436"/>
<Rectangle Fill="#FF2F5151" HorizontalAlignment="Left" Height="98" Margin="10,537,0,0" Stroke="Black" VerticalAlignment="Top" Width="217"/>
<Rectangle Fill="#FF1E7870" HorizontalAlignment="Left" Height="108" Margin="237,537,0,0" Stroke="Black" VerticalAlignment="Top" Width="209"/>
</StackPanel>
</ScrollViewer>
用StackPanel替换网格并定位矩形
<ScrollViewer Height="400" VerticalScrollBarVisibility="Auto" >
<StackPanel VerticalAlignment="Top" >
<Rectangle Fill="#FF283742" HorizontalAlignment="Left" Height="184" Margin="10,0,0,0" Stroke="Black" VerticalAlignment="Top" Width="436"/>
<Rectangle Fill="#FF876D6D" HorizontalAlignment="Left" Height="130" Margin="10,192,0,0" Stroke="Black" VerticalAlignment="Top" Width="217"/>
<Rectangle Fill="#FF565D41" HorizontalAlignment="Left" Height="133" Margin="237,189,0,0" Stroke="Black" VerticalAlignment="Top" Width="209"/>
<Rectangle Fill="#FF322929" HorizontalAlignment="Left" Height="205" Margin="10,327,0,0" Stroke="Black" VerticalAlignment="Top" Width="436"/>
<Rectangle Fill="#FF2F5151" HorizontalAlignment="Left" Height="98" Margin="10,537,0,0" Stroke="Black" VerticalAlignment="Top" Width="217"/>
<Rectangle Fill="#FF1E7870" HorizontalAlignment="Left" Height="108" Margin="237,537,0,0" Stroke="Black" VerticalAlignment="Top" Width="209"/>
</StackPanel>
</ScrollViewer>
用StackPanel替换网格并定位矩形
<ScrollViewer Height="400" VerticalScrollBarVisibility="Auto" >
<StackPanel VerticalAlignment="Top" >
<Rectangle Fill="#FF283742" HorizontalAlignment="Left" Height="184" Margin="10,0,0,0" Stroke="Black" VerticalAlignment="Top" Width="436"/>
<Rectangle Fill="#FF876D6D" HorizontalAlignment="Left" Height="130" Margin="10,192,0,0" Stroke="Black" VerticalAlignment="Top" Width="217"/>
<Rectangle Fill="#FF565D41" HorizontalAlignment="Left" Height="133" Margin="237,189,0,0" Stroke="Black" VerticalAlignment="Top" Width="209"/>
<Rectangle Fill="#FF322929" HorizontalAlignment="Left" Height="205" Margin="10,327,0,0" Stroke="Black" VerticalAlignment="Top" Width="436"/>
<Rectangle Fill="#FF2F5151" HorizontalAlignment="Left" Height="98" Margin="10,537,0,0" Stroke="Black" VerticalAlignment="Top" Width="217"/>
<Rectangle Fill="#FF1E7870" HorizontalAlignment="Left" Height="108" Margin="237,537,0,0" Stroke="Black" VerticalAlignment="Top" Width="209"/>
</StackPanel>
</ScrollViewer>