2010-03-10 69 views
1

我該如何去創建一個控件,該項目的項目垂直列出,但僅限於控件的高度,然後從第二列的頂部開始?WPF創建一個垂直滾動然後水平滾動的項目列表

有點像Windows資源管理器的外觀和感覺。

我使用的是WrapPanel的時刻,但我無法弄清楚如何使它水平滾動...

這裏任何幫助是極大的讚賞

乾杯, 馬克

回答

2

附上一個WrapPanel,垂直方向在ScrollViewer內,VerticalScrollbarVisibility設置爲Disabled

粘貼到這個Kaxaml,你會看到:

<Page 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <Page.Resources> 
    <Style TargetType="{x:Type Button}"> 
     <Style.Setters> 
     <Setter Property="Width" Value="50"/> 
     <Setter Property="Height" Value="50"/> 
     </Style.Setters> 
    </Style> 
    </Page.Resources> 
    <Grid Margin="200, 100"> 
    <ScrollViewer VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Visible" MaxWidth="200"> 
    <WrapPanel Orientation="Vertical"> 
     <Button/> 
     <Button/> 
     <Button/> 
     <Button/> 
     <Button/> 
     <Button/> 
     <Button/> 
     <Button/> 
     <Button/> 
    </WrapPanel> 
    </ScrollViewer> 
    </Grid> 
</Page> 
+0

如果將VerticalScrollBarVisibility設置爲Disabled,則不需要設置MaxHeight。 – 2010-03-10 19:39:22

+0

固定。出於某種原因,我忘記了'Visibility.Disabled'即使存在。 – 2010-03-10 20:05:17

+0

工作得很好,雖然我有一些初步的麻煩,我使用的是Canvas而不是網格,並且當wrappanel中有很多內容時滾動條沒有顯示,爲什麼? – Mark 2010-03-10 21:43:40

0

聲音很像一個UniformGrid或WrapPanel給我 檢查這個blog,他有一些很好的內置佈局面板的演示

+0

與唯一的問題是,WrapPanel犯規滾動,我需要它,和Im假設同爲UniformGrid ... – Mark 2010-03-10 08:59:46