WPF 导航窗口滚动条

发布于 2024-12-01 16:25:31 字数 162 浏览 1 评论 0原文

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

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

I have seen a few posts here that ask about WPF scrollbars and the answer is usually to use a ScrollViewer. The problem with this is, I can only get it to work with a statically sized window. If the window is resized, the scrollviewer gets cut off.

I would like for the NavigationWindow scrollbars to appear, any tips? I'm writing an application that needs to work on a variety of display resolutions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

惯饮孤独 2024-12-08 16:25:31

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

最后的简单解决方案:)

It turns out that if you set the size of a Page control, then a scrollviewer will not resize with the window as it's resized. If you have the following code, your scrollviewers will not work right:

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

If you simply leave out the page height and width properties as follows, it will work fine:

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

Simple solution in the end :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文