在网格大小中使用 * 时出现问题
当我将列的宽度或行的高度设置为星形,并且填充大于可用矩形的内容时,该行会继续在“地下”增长:
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="100" Width="100">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel>
<Button Content="Button" />
<Button Content="Button" />
<Button Content="Button" />
</StackPanel>
<StackPanel Grid.Row="1"
ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.IsDeferredScrollingEnabled="True">
<Button Content="Button" />
<Button Content="Button" />
<Button Content="Button" />
</StackPanel>
</Grid>
</Window>
我希望 StackPanel 不应该在地下增长,而是应该显示滚动条。
请注意,我需要所有动态大小,因此一切都会根据用户调整父级大小而变化。
我对列也有同样的问题。
附言。 RowDefinition.Height 默认情况下始终为 *。
更新
我猜问题是网格,我发布的上一个片段没有提供整个故事,请查看:
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="200">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition/>
<RowDefinition Height="20"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="1">
<StackPanel>
<TextBlock Text="Hello"/>
<TextBox Text="World!"/>
</StackPanel>
<ScrollViewer>
<StackPanel>
<Button Content="Button"/>
<Button Content="Button"/>
<Button Content="Button"/>
<Button Content="Button"/>
<Button Content="Button"/>
</StackPanel>
</ScrollViewer>
</StackPanel>
</Grid>
</Window>
When I set a column's width or a row's height to star, and I fill in content that is bigger than the available rectangle, the row keeps on growing 'underground':
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="100" Width="100">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel>
<Button Content="Button" />
<Button Content="Button" />
<Button Content="Button" />
</StackPanel>
<StackPanel Grid.Row="1"
ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.IsDeferredScrollingEnabled="True">
<Button Content="Button" />
<Button Content="Button" />
<Button Content="Button" />
</StackPanel>
</Grid>
</Window>
I want that StackPanel should not grow underground, instead it should show scrollbars.
Note, I need all the size dynamic so everything changes according to the user resizing the parents.
I have the same issue with columns.
PS. RowDefinition.Height is always * by default.
UPDATE
I guess the problem is the grid and the previous snippet I posted didn't provide the whole story, please review:
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="200">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition/>
<RowDefinition Height="20"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="1">
<StackPanel>
<TextBlock Text="Hello"/>
<TextBox Text="World!"/>
</StackPanel>
<ScrollViewer>
<StackPanel>
<Button Content="Button"/>
<Button Content="Button"/>
<Button Content="Button"/>
<Button Content="Button"/>
<Button Content="Button"/>
</StackPanel>
</ScrollViewer>
</StackPanel>
</Grid>
</Window>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定 StackPanel 是否有内置的 ScrollViewer,因此设置附加的 ScrollViewer.* 属性实际上对其没有任何影响。
您是否尝试过使用
ScrollViewer
显式包装StackPanel
?例如:I'm not sure that
StackPanel
has a built inScrollViewer
so setting theScrollViewer.*
attached proeprties really has no effect on it.Have you tried wrapping the
StackPanel
with aScrollViewer
explicitly? For example: