【发布时间】:2014-04-07 15:46:17
【问题描述】:
我有一个宽度 = 1400 的面板,它包含宽度 = 700 的较小面板。如果屏幕为全宽,则较小的面板应以每行 2 个显示,否则应换行并出现垂直滚动条。
使用下面的代码,内容被包装但没有滚动条:
<StackPanel Grid.Column="1" Grid.Row="1" Width="1400">
<ScrollViewer x:Name="body" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<WrapPanel Orientation="Horizontal" MaxHeight="700" Width="{Binding ElementName=body, Path=ViewportWidth}">
<Border BorderBrush="Black" BorderThickness="1" Width="700" Height="400">
</Border>
<Border BorderBrush="Black" BorderThickness="1" Width="700" Height="400">
</Border>
<Border BorderBrush="Black" BorderThickness="1" Width="700" Height="400">
</Border>
<Border BorderBrush="Black" BorderThickness="1" Width="700" Height="400">
</Border>
</WrapPanel>
</ScrollViewer>
</StackPanel>
我做错了什么?
编辑
建议的解决方案无效。我当前的代码:
<StackPanel Grid.Column="1" Grid.Row="1" Background="#FFEAEEFC">
<ScrollViewer x:Name="body" HorizontalScrollBarVisibility="Disabled">
<WrapPanel Margin="10" MaxWidth="1400">
<Border BorderBrush="Black" BorderThickness="1" Width="700" Height="400">
</Border>
<Border BorderBrush="Black" BorderThickness="1" Width="700" Height="400">
</Border>
<Border BorderBrush="Black" BorderThickness="1" Width="700" Height="400">
</Border>
<Border BorderBrush="Black" BorderThickness="1" Width="700" Height="400">
</Border>
</WrapPanel>
</ScrollViewer>
</StackPanel>
【问题讨论】:
标签: wpf stackpanel word-wrap