我想在我的程序中使用一個簡單的ScrollViewer,但我遇到了問題。WPF ScrollViewer問題
如果我在一個ScrollViewer中附上我的程序中的一切,它工作正常:
<Window x:Class="WpfTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Name="PrimaryWindow">
<ScrollViewer>
<StackPanel>
<Menu Height="21" VerticalAlignment="Top">
<MenuItem Header="File"/>
<MenuItem Header="Edit"/>
</Menu>
<StackPanel>
<TextBlock Text="1"/>
<TextBlock Text="2"/>
<TextBlock Text="3"/>
<TextBlock Text="4"/>
<TextBlock Text="5"/>
<TextBlock Text="6"/>
<TextBlock Text="7"/>
<TextBlock Text="8"/>
<TextBlock Text="9"/>
<TextBlock Text="10"/>
</StackPanel>
</StackPanel>
</ScrollViewer>
</Window>
然而,由於菜單是ScrollViewer中,菜單滾動出屏幕的一部分用戶向下滾動時。所以我把ScrollViewer只放在菜單下面的控件上:
<Window x:Class="WpfTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Name="PrimaryWindow">
<StackPanel>
<Menu Height="21" VerticalAlignment="Top">
<MenuItem Header="File"/>
<MenuItem Header="Edit"/>
</Menu>
<ScrollViewer>
<StackPanel>
<TextBlock Text="1"/>
<TextBlock Text="2"/>
<TextBlock Text="3"/>
<TextBlock Text="4"/>
<TextBlock Text="5"/>
<TextBlock Text="6"/>
<TextBlock Text="7"/>
<TextBlock Text="8"/>
<TextBlock Text="9"/>
<TextBlock Text="10"/>
</StackPanel>
</ScrollViewer>
</StackPanel>
</Window>
但是這一次,ScrollViewer不起作用!即使我調整窗口的尺寸使其小於標籤所需的高度,滾動條也不會被激活。
我在做什麼錯?
謝謝,工作! – HighCommander4