2011-08-25 93 views
0

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

我想让NavigationWindow滚动条出现,任何提示?我正在编写一个需要处理各种显示分辨率的应用程序。

+0

发布一些不适合你的xaml。我怀疑你的ScroolView没有配置为填充容器的大小。 – Paparazzi

+0

果然,我试图为你制作一个样品,当然这个样品也是工作的。我会发布一个解决方案,说明为什么我的原始代码不起作用以及为什么我的样本没有。 – Eric

回答

0

事实证明,如果您设置页面控件的大小,那么在调整大小时,scrollviewer将不会随窗口调整大小。如果你有下面的代码,你的scrollviewers将无法正常工作:

<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> 

简单的解决方案结束:)