0

我在这里看到了一些询问 WPF 滚动条的帖子,答案通常是使用 ScrollViewer。问题是,我只能让它与静态大小的窗口一起工作。如果调整窗口大小,则滚动查看器会被切断。

我希望出现 NavigationWindow 滚动条,有什么提示吗?我正在编写一个需要在各种显示分辨率下工作的应用程序。

4

1 回答 1

0

事实证明,如果您设置 Page 控件的大小,则滚动查看器在调整大小时不会随窗口一起调整大小。如果您有以下代码,您的滚动查看器将无法正常工作:

<Page x:Class="SomeNamespace.SamplePage"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  mc:Ignorable="d" Title="SamplePage" Height="400" Width="400">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
    <ScrollViewer HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalScrollBarVisibility="Auto">
        <Border x:Name="BigBadBorder" Height="1000" Width="2000" Background="HotPink" Margin="5">
            <TextBlock Text="Waldo" HorizontalAlignment="Center" VerticalAlignment="Center"/>
        </Border>
    </ScrollViewer>
</Grid>
</Page>

如果您简单地省略页面高度和宽度属性,如下所示,它将正常工作:

<Page x:Class="SomeNamespace.SamplePage"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  mc:Ignorable="d" Title="SamplePage">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
    <ScrollViewer HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalScrollBarVisibility="Auto">
        <Border x:Name="BigBadBorder" Height="1000" Width="2000" Background="HotPink" Margin="5">
            <TextBlock Text="Waldo" HorizontalAlignment="Center" VerticalAlignment="Center"/>
        </Border>
    </ScrollViewer>
</Grid>
</Page>

最后的简单解决方案:)

于 2011-08-26T16:39:03.370 回答