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