我在 ScrollViewer 中有一个图像。当我将图像宽度设置得更大时,出现了 HorizontalScrollBar。然后我将图像宽度设置为小于 ScrollViewer With 但此 ScrollBar 仍然出现,如下所示:
我该如何解决这个问题?谢谢!
<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;
}
}