Scrollviewer 与 Dockpanel 存在问题
我使用 Dockpanel 作为布局的主面板。顶部的工具栏设置为顶部,而侧面板设置为左侧。文档查看器设置为由 LastChildFill 填充。
问题是滚动查看器的高度不会随着窗口大小的调整而缩放。只有文档查看器可以。它似乎只会随着子内容的增加而扩展。我正在尝试模仿 Google Chrome 的打印布局。当子项没有溢出窗口时,就没有滚动条,但如果它小于窗口,滚动条将填满窗口。
这是代码:
<ToolBar Width="Auto" Height="35" DockPanel.Dock="Top" VerticalAlignment="Top" HorizontalAlignment="Stretch" Panel.ZIndex="10" Background="White">
<StackPanel Margin="5,0,0,0" Orientation="Horizontal">
<Button Content="New" Style="{StaticResource MenuItem}"/>
<Button Content="Save" Style="{StaticResource MenuItem}"/>
<Button Content="Print" Style="{StaticResource MenuItem}"/>
<Button Content="Delete" Style="{StaticResource MenuItem}"/>
<Button Content="Export" Style="{StaticResource MenuItem}"/>
<Border Style="{StaticResource SeparatorStyle}"/>
<Button Content="Burn DVD" Style="{StaticResource MenuItem}"/>
<Button Content="Open Folder" Style="{StaticResource MenuItem}"/>
<Border Style="{StaticResource SeparatorStyle}"/>
<Button Content="Next Patient" Style="{StaticResource MenuItem}"/>
</StackPanel>
</ToolBar>
<ScrollViewer Background="White" x:Name="SidePanel" HorizontalAlignment="Left" Margin="0" VerticalAlignment="Top" Width="400" DockPanel.Dock="Left" Panel.ZIndex="2" Padding="10">
<StackPanel>
<StackPanel.Resources>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Margin" Value="0,10,0,0"/>
</Style>
</StackPanel.Resources>
<Label Content="Patient Report" Style="{StaticResource SidePanel_H1}" />
<Rectangle Style="{StaticResource SidePanel_HR}" />
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
</StackPanel>
</ScrollViewer>
<Rectangle Height="Auto" Width="2" DockPanel.Dock="Left" Fill="#FFA0A0A0"/>
<DocumentViewer x:Name="dv1" AllowDrop="False" Cursor="Hand" Loaded="dv1_Loaded" MinWidth="600">
<FixedDocument Focusable="False" x:Name="FD">
</FixedDocument>
</DocumentViewer>
</DockPanel>
I'm using a Dockpanel as my main panel for my layout. The toolbar on top is set to top, while the side panel is set to left. The documentviewer is set to fill by LastChildFill.
The problem is that the height of the scrollviewer doesn't scale as the window resizes. Only the documentviewer does. It seems to only scale as the child content increases. I'm trying to mimic Google Chrome's Print layout. When the children does not overflow the window then there is no scrollbar but if it's less than the window, the scrollbars would fill up the window.
Here's the code:
<ToolBar Width="Auto" Height="35" DockPanel.Dock="Top" VerticalAlignment="Top" HorizontalAlignment="Stretch" Panel.ZIndex="10" Background="White">
<StackPanel Margin="5,0,0,0" Orientation="Horizontal">
<Button Content="New" Style="{StaticResource MenuItem}"/>
<Button Content="Save" Style="{StaticResource MenuItem}"/>
<Button Content="Print" Style="{StaticResource MenuItem}"/>
<Button Content="Delete" Style="{StaticResource MenuItem}"/>
<Button Content="Export" Style="{StaticResource MenuItem}"/>
<Border Style="{StaticResource SeparatorStyle}"/>
<Button Content="Burn DVD" Style="{StaticResource MenuItem}"/>
<Button Content="Open Folder" Style="{StaticResource MenuItem}"/>
<Border Style="{StaticResource SeparatorStyle}"/>
<Button Content="Next Patient" Style="{StaticResource MenuItem}"/>
</StackPanel>
</ToolBar>
<ScrollViewer Background="White" x:Name="SidePanel" HorizontalAlignment="Left" Margin="0" VerticalAlignment="Top" Width="400" DockPanel.Dock="Left" Panel.ZIndex="2" Padding="10">
<StackPanel>
<StackPanel.Resources>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Margin" Value="0,10,0,0"/>
</Style>
</StackPanel.Resources>
<Label Content="Patient Report" Style="{StaticResource SidePanel_H1}" />
<Rectangle Style="{StaticResource SidePanel_HR}" />
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
<TextBox Text="DATA"/>
</StackPanel>
</ScrollViewer>
<Rectangle Height="Auto" Width="2" DockPanel.Dock="Left" Fill="#FFA0A0A0"/>
<DocumentViewer x:Name="dv1" AllowDrop="False" Cursor="Hand" Loaded="dv1_Loaded" MinWidth="600">
<FixedDocument Focusable="False" x:Name="FD">
</FixedDocument>
</DocumentViewer>
</DockPanel>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设置
VerticalAlignment="Stretch"
或删除该属性就可以了。DockPanel
仅影响停靠子项的一个方向。在你的情况下,它是水平的。Set
VerticalAlignment="Stretch"
or remove the attribute and you'll be fine.DockPanel
affects only one direction for docked children. In your case, it's horizontal.