0
我在ScrollViewer中有一个图像。当我设置图像宽度更大时,HorizontalScrollBar出现。然后,我设置图像宽度小于ScrollViewer中采用,但这种滚动条仍然会出现,就像这样:WPF ScrollViewer HorizontalScrollBar不能正常工作
我怎么能解决这个问题?谢谢!
<Grid>
<ScrollViewer
Name="sv"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto"
PreviewMouseWheel="sv_PreviewMouseWheel">
<Image Name="img"/>
</ScrollViewer>
</Grid>
代码:
void sv_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
if ((System.Windows.Forms.Control.ModifierKeys & System.Windows.Forms.Keys.Control) != System.Windows.Forms.Keys.Control) base.OnMouseWheel(e);
else
{
if (e.Delta > 0)
{
if (img.ActualHeight < img.Source.Height * 5)
{
double h2 = img.Height = img.ActualHeight * 1.1;
double w2 = img.Width = img.Source.Width * h2/img.Source.Height;
}
}
// PROBLEM HERE:
else if (img.ActualHeight > 100) img.Height = img.ActualHeight/1.1;
}
}
谢谢!它工作正常:) – Sakura
此外,你应该看看使用'ScaleTransform'来代替。简单得多。 –
我不知道如何使用它,我是WPF的新手,你能否给我一个相对于我上面的任务的示例链接? – Sakura