2014-04-01 61 views
1

我有以下ItemsControl避免滾動以下重點MVVM

<ItemsControl ItemsSource="{Binding Model.XList}"> 
    <ItemsControl.ItemsPanel> 
    <ItemsPanelTemplate> 
     <StackPanel Orientation="Horizontal"></StackPanel> 
    </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 
</ItemsControl> 

在他們每個人都適用以下模板:

<DataTemplate DataType="{x:Type model:MyModelType}"> 
    <Border MaxWidth="140"> 
     <local:SingleView DataContext="{Binding}"/> 
    </Border> 
</DataTemplate> 

他們每個人實際上使「SingleView」控制。

ItemsControl裹在ScrollViewer

當我有大量的項目(滾動似乎),並按下控件的任何按鈕,屏幕跳轉(可能是因爲獲取焦點的滾動已更改)。

我想避免焦點後面的滾動。

我見過的解決方案使其通過代碼隱藏,通過RequestBringIntoView事件。

但我正在與MVVM,沒有人有解決方案嗎?

+0

'我見過的解決方案,使它通過代碼隱藏,通過RequestBringIntoView event.' - 你能展示這個解決方案嗎? –

+0

@AnatoliyNikolaev,看看這裏:http://stackoverflow.com/questions/209416/in-a-wpf-listview-how-can-i-prevent-auto-scrolling –

+0

你試過ScrollViewer.CanContentScroll =「False」 '爲ItemsControl'?你見過['this'](http://serialseb.blogspot.ru/2007/09/wpf-tips-6-preventing-scrollviewer-from.html)方法嗎?該方法適用於MVVM。 –

回答

2

什麼幫助我是爲了避免接收注重ItemsControl

(如果有到ItemsControl的,所以你才能避免焦點也有包裝)

<ItemsControl ItemsSource="{Binding Model.XList}" Focusable="False"> 
    <ItemsControl.ItemsPanel> 
    <ItemsPanelTemplate> 
     <StackPanel Orientation="Horizontal"></StackPanel> 
    </ItemsPanelTemplate> 
    </ItemsControl.ItemsPanel> 
</ItemsControl>