[英]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.