我嘗試創建一個滾動的水平StackPanel的,但我沒有成功很好...爲StackPanel中水平滾動不起作用
目前,我有我有auto
寬度的StackPanel(而問題是,也許在這裏)其中包含一些項目,如grids
。
現在,如果我的所有網格在stackpanel中都不可見(寬度太短),我無法滾動。 我已經嘗試將堆棧面板放入ScrollViewer
中,但它不會在' 中工作。
我該如何dix呢?由於
編輯這裏是我的代碼:
<StackPanel Height="85" Margin="0,0,200,15" VerticalAlignment="Bottom">
<ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Disabled" HorizontalAlignment="Left" Height="85" CanContentScroll="True">
<StackPanel x:Name="Film" Height="85" Width="Auto" Margin="0,0,0,0" Orientation="Horizontal" ScrollViewer.HorizontalScrollBarVisibility="Visible" CanHorizontallyScroll="True" ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.CanContentScroll="True" d:LayoutOverrides="TopPosition, BottomPosition">
<StackPanel.Background>
<SolidColorBrush Color="{DynamicResource ButtonBackground}"/>
</StackPanel.Background>
<Grid Width="100" Background="Red"/>
<Grid Width="100" Background="#FFFF0051"/>
<Grid Width="100" Background="#FFB900FF"/>
<Grid Width="100" Background="#FF002EFF"/>
<Grid Width="100" Background="#FF00FFDC"/>
<Grid Width="100" Background="#FF51FF00"/>
<Grid Width="100" Background="Red"/>
</StackPanel>
</ScrollViewer>
</StackPanel>
什麼是堆棧面板的祖先?你不能有自動寬度 – gmetax
檢查滾動查看該線程它會幫助你http://stackoverflow.com/questions/19355818/how-to-make-scrollviewer-work-with-height-set-to-auto-in- wpf – gmetax
它不能工作,除非你真的把整個東西放在ScrollViewer中。 – Clemens