我在滚动查看器中使用鼠标滚轮滚动时遇到问题。 看来,如果鼠标光标位于滚动条的不包含任何UI元素的区域上方,则滚动不起作用。鼠标滚轮无法正常使用ScrollViwer
在附加的例子中,我使用具有大边距的矩形填充滚动查看器。当鼠标光标在一个矩形滚动上方时,但是当它超出边界时,不会发生滚动。
任何想法如何解决这个问题?
XAML:
<UserControl x:Class="SilverlightApplication229.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<StackPanel x:Name="MyPanel" />
</ScrollViewer>
</Grid>
</UserControl>
代码:
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
for (int i = 0; i < 100; i++)
{
Rectangle rect = new Rectangle { Width = 100, Height = 100, Fill = new SolidColorBrush(Colors.Red), Margin = new Thickness(50) };
MyPanel.Children.Add(rect);
}
}
}
谢谢!
最近我遇到了一个错误,解决方案可能是为scrollviewer添加背景。使用透明背景Silverlight可能认为鼠标在背景上而不是滚动查看器。我不确定这个答案,但它会很快并且很容易测试。 – StephenT