【问题标题】:Avoid scrolling following the focus on MVVM避免在关注 MVVM 后滚动
【发布时间】:2014-04-01 04:57:23
【问题描述】:

我有以下ItemsControl

<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”控件。

包裹在ScrollViewer中的ItemsControl。

当我有大量的项目(滚动似乎),并且我按下控件的任何按钮时,屏幕会跳转(可能是因为获得焦点的滚动发生了变化)。

我想避免跟随焦点滚动。

我已经看到通过 RequestBringIntoView 事件通过 Code-Behind 实现的解决方案。

但我正在与 MVVM 合作,有人对此有解决方案吗?

【问题讨论】:

  • I've seen solutions that make it through the Code-Behind, by RequestBringIntoView event. - 你能展示这个解决方案吗?
  • @AnatoliyNikolaev,看这里:stackoverflow.com/questions/209416/…
  • 你试过ScrollViewer.CanContentScroll="False"ItemsControl 吗?你见过this 方法吗?此方法适用于 MVVM。

标签: wpf mvvm scroll itemscontrol


【解决方案1】:

帮助我避免关注ItemsControl

(如果 ItemsControl 有一个包装器,那么您也可以避免在那里获得焦点)

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

【讨论】:

    猜你喜欢
    • 2011-07-20
    • 1970-01-01
    • 2018-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-06
    相关资源
    最近更新 更多