c# - 如何自动滚动到包装面板中的特定项目?

标签 c# scroll wrappanel

目前,我在一个大型软件项目中进行协作,但我在尝试实现一个不错的功能时遇到了问题。

问题是,我不知道如何自动滚动到某个用户可以选择的特定项目。包装面板用作项目控件中的项目面板模板。

为了更好地理解以下代码:

<ItemsControl ItemsSource="{Binding SomeData}">
   <ItemsControl.ItemsPanel>
      <ItemsPanelTemplate>
         <WrapPanel />
      </ItemsPanelTemplate>
   </ItemsControl.ItemsPanel>
   <ItemsControl.ItemTemplate>
      <DataTemplate>
         <SomeChart DataContext="{Binding }" Focusable="True" />
      </DataTemplate>
   </ItemsControl.ItemTemplate>
</ItemsControl>

最佳答案

您提到了 ItemsControl,大多数从 ItemsControl 派生的控件都有一个 ScrollIntoView 方法将列表框/数据网格滚动到当前选定的项目。

例如:

listBox1.ScrollIntoView(listBox1.SelectedIndex);

dataGrid1.ScrollIntoView(dataGrid1.SelectedIndex);

这是 ListView 的另一个解决方案.

更新: 带包装板的列表框

<ListBox x:Name="myList">
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel ItemHeight="150" ItemWidth="150"/>
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
</Listbox>

关于c# - 如何自动滚动到包装面板中的特定项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13468878/

相关文章:

wpf - ListBox+WrapPanel 方向键导航

wpf - 使用 MVVM 是从 View 模型添加控件以包装面板的好习惯吗?

c# - Silverlight WrapPanel 不会在 Accordion 内部垂直拉伸(stretch)

c# - Azure 移动服务 token 有效期

c# - 使用与 Windows 设置不同的货币格式

c# - 以编程方式在 C# DataGridView 中设置记录指针

javascript - 如何使用箭头键禁用 FF 中的页面滚动

在用户交互之前,Android WebView 无法完全呈现内容

c# - 使用属性... INotifyPropertyChanged

html - 如何在 componentDidMount 中将 div 滚动到底部(使用 react.js)?