2015-05-19 92 views
0

裏面我嘗試在我的窗口中顯示的圖像:WPF無法滾動的圖像的ScrollViewer

<Window x:Class="Problem.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" Height="350" Width="525"> 
    <DockPanel> 
     <StackPanel Orientation="Vertical"> 
      <ScrollViewer VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible"> 
       <Image Source="cat.jpg" Stretch="Uniform"> 
        <Image.LayoutTransform> 
         <RotateTransform Angle="90" /> 
        </Image.LayoutTransform> 
       </Image> 
      </ScrollViewer> 
     </StackPanel> 
    </DockPanel> 
</Window> 

其中cat.jpg爲1920×1080的圖像。

下面是結果:

enter image description here

正如你所看到的,是VerticalScrollbar雖然我不能看到完整的貓頭禁用。此外,HorisontalScrollBar是隱形的。

我的問題是:如何啓用滾動條來滾動我的圖片?

回答

5

刪除StackPanel。它給它的內容無限的空間,所以ScrollViewer有圖像的高度。如果你需要的圖像下堆放的東西,創造一個StackPanelScrollViewer

<Window x:Class="Problem.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="MainWindow" Height="350" Width="525"> 
<DockPanel> 
    <ScrollViewer VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible"> 
     <StackPanel> 
      <Image Source="cat.jpg" Stretch="Uniform"> 
       <Image.LayoutTransform> 
        <RotateTransform Angle="90" /> 
       </Image.LayoutTransform> 
      </Image> 
     </StackPanel> 
    </ScrollViewer> 
</DockPanel> 

+0

在我真正的代碼,我需要在我的形象 – Epitouille

+0

以層疊的ButtonBar那麼你應該移動的StackPanel內ScrollViewer中。 – Domysee

+0

我編輯了代碼來表示這個 – Domysee