2011-07-24 111 views
1

一些背景: 我們正在嘗試構建一些調度控件,如使用某些自定義功能的Outlook。 我已經閱讀了代碼項目中的類似帖子,但我們傾向於採取稍微不同的方法(嘗試使用MVVM方法)。在嵌套列表框中滾動wpf

問題: 目前我們有一個3個項目的列表框。列表框中的每個項目都是以邊框爲項目的另一個列表框。例如,在XAML代碼看起來像這樣

<ListBox Name="MasterListBox" HorizontalAlignment="Stretch" Height="500" Width="500"> 
       <ListBox.ItemsPanel> 
      <ItemsPanelTemplate> 
       <StackPanel Orientation="Horizontal"/> 
      </ItemsPanelTemplate> 
     </ListBox.ItemsPanel> 
     <ListBoxItem > 
      <ListBox Name="Child1" Height="240"> 
       <ListBoxItem> 
        <Border Width="200" Background="Red" Height="40"></Border> 
       </ListBoxItem> 
       <ListBoxItem > 
        <Border Width="200" Background="Blue" Height="40"></Border> 
       </ListBoxItem> 
       <ListBoxItem > 
        <Border Width="200" Background="Green" Height="40"></Border> 
       </ListBoxItem> 
      </ListBox> 
     </ListBoxItem> 
     <ListBoxItem > 
      <ListBox Name="Child2" Height="240"> 
       <ListBoxItem > 
        <Border Width="200" Background="Yellow" Height="40"></Border> 
       </ListBoxItem> 
       <ListBoxItem > 
        <Border Width="200" Background="Green" Height="40"></Border> 
       </ListBoxItem> 
       <ListBoxItem > 
        <Border Width="200" Background="Pink" Height="40"></Border> 
       </ListBoxItem> 
      </ListBox> 
     </ListBoxItem> 
     <ListBoxItem > 
      <ListBox Name="Child3" Height="240"> 
       <ListBoxItem > 
        <Border Width="200" Background="Aqua" Height="40"></Border> 
       </ListBoxItem> 
       <ListBoxItem > 
        <Border Width="200" Background="Beige" Height="40"></Border> 
       </ListBoxItem> 
       <ListBoxItem > 
        <Border Width="200" Background="Brown" Height="40"></Border> 
       </ListBoxItem> 
      </ListBox> 
     </ListBoxItem> 
</ListBox> 

問題是,當我在空白區域單擊MasterListBox的第一個項目(Child1)和向右拖動,在MasterListBox列表框滾動到右,但是當我點擊該子項(例如說紅色邊框)並向右拖動MasterListBox不向右滾動。 我知道我試圖拖動內部列表框的項目,這就是外部列表框不滾動的原因,但它有一種方法,我們可以重寫這個。我想選擇內部項目,所以不能爲內部項目設置IsHitTestVisible =「False」。

感謝您關注此事。非常感謝您的幫助。

問候
SAURABH

回答

0

一個做到這一點的方法是使用內ListBoxOnPreviewLeftMouseDownOnPreviewMouseMoveOnPreviewMouseUp事件來實現預期的效果,以創建拖動以滾動功能。

另一種方法是查找負責內部ListBox內的拖動滾動功能的事件並覆蓋事件處理程序,以便事件獲取路由到外部ListBox

+0

謝謝Jakub看看。但請你能詳細說明你的方法。我對WPF的效率不是很高,所以如果你可以通過重寫事件處理程序讓我知道一些關於你的意思的細節。如果可能的話,你可以指示我到任何你知道的鏈接或例子。再次感謝您的回覆 – SD13