2012-01-01 49 views
1

嗨,感謝您的期待!如何屏蔽WPF Wrappanel的內容?

背景

這是對這個問題的延伸:

How do I slide child items up or down inside a WPF wrappanel?

在我問我怎麼能programattically滾動WrapPanel內容上的按鈕點擊向上或向下。這個問題很好地回答了,並且接受的解決方案運作良好。

問題

現在,我在WrapPanel滾動縮略圖上下按鈕上點擊,我怎麼掩蓋WrapPanel,這樣當他們框外的地磚不顯示?例如,我在WrapPanel上方有一個StackPanel,它擁有向上和向下滾動按鈕,但當向下滾動時,縮略圖會覆蓋它們上方的StackPanel(和按鈕)。這裏是我的XAML到目前爲止,請注意,縮略圖被添加到WrapPanel在運行時:

更新

使用大衛克萊默的XAML,我的佈局是穩定的,但後來我還是結束了的內容WrapPanel通過上面的StackPanel。請參閱前後滾動事件採取的這些屏幕抓取:

之前滾動功能的

Before Scroll

後無滾動 enter image description here

更新2

設置畫布紅色背景根據戴夫的評論如下。

之前滾動功能的

enter image description here

後無滾動

enter image description here

+0

感謝您的編輯,戴夫。這只是教會了我幾件事。未來的問題會更好看!乾杯。 – 2012-01-01 20:27:36

+0

如果您需要滾動幫助,則需要使用ScrollViewer發佈XAML。 – Paparazzi 2012-01-01 20:38:56

+0

我的榮幸。那麼,你想要滾動WrapPanel而不是上面的StackPanel?如果是的話,它會更容易做一些沿的方法1線條更在你前面的問題,並再次把一切都放在一個網格,與StackPanel中在0行和WrapPanel與ScrollViewer中第1行中 – 2012-01-01 20:39:15

回答

2

好了,我不會把這種直觀的,但最終,這個工作:

<Border Grid.Row="1" Background="Transparent" ClipToBounds="True">  
      <Canvas> 
       <WrapPanel x:Name="spContainer" 
        Width="{Binding ActualWidth, 
          RelativeSource={RelativeSource AncestorType={x:Type Canvas}}}"> 
       </WrapPanel> 
      </Canvas> 
</Border> 

添加邊框的伎倆。感謝戴夫爲您提供的所有幫助!

+0

很高興工作。 – 2012-01-01 22:07:48

+0

再次感謝戴夫。如果沒有你的幫助,我不可能得到那裏。 – 2012-01-01 22:15:30

+0

是不是已經足以在畫布上指定cliptobound? – flq 2012-01-01 22:37:31

1

這聽起來像你不想滾動條(無ScrollViewer),並希望StackPanel加以固定。請單獨Grid行如StackPanelWrapPanel

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="Auto" /> 
     <RowDefinition Height="*"/> 
    </Grid.RowDefinitions> 
    <StackPanel Grid.Row="0" Height="150" HorizontalAlignment="Left" Margin="30,10,10,10" Name="stackPanel1" VerticalAlignment="Top" Width="Auto" Orientation="Horizontal" > 
     <Label Content="Home Navigator v0.1" FontFamily="Tahoma" FontSize="30" FontWeight="Bold" Foreground="White" /> 
     <Button Content="Close" Height="50" Click="Button_Click" VerticalAlignment="Top"></Button> 
     <Button Content="Scroll Down" Height="50" Click="ScrollDown" VerticalAlignment="Top"></Button> 
    </StackPanel> 
    <Canvas Grid.Row="1"> 
     <WrapPanel x:Name="spContainer" 
        Width="{Binding ActualWidth, 
          RelativeSource={RelativeSource AncestorType={x:Type Canvas}}}"> 
     </WrapPanel>  
    </Canvas> 
</Grid> 
+0

感謝戴夫,您建議的XAML有助於製作更好的佈局,但我仍然遇到原始問題。請參閱上面的我的更新。 – 2012-01-01 21:13:50

+0

嗯,奇怪。要麼你在Canvas之外的AnimateScroll方法或其他地方渲染圖像,要麼(我懷疑),Canvas會在其網格行之外展開。你能確定它是哪些問題嗎(比如在你的Canvas上放置一個紅色背景)? – 2012-01-01 21:30:07

+0

請看上面的新屏幕截圖,戴夫。再次感謝! – 2012-01-01 21:35:03