繁体   English   中英

WPF NavigationWindow滚动条

[英]WPF NavigationWindow scrollbar

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

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

事实证明,如果您设置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>

如果您只是简单地省略了页面的height和width属性,则可以正常工作:

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

最终的简单解决方案:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM