2011-08-25 94 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> 

簡單的解決方案結束:)