目前,我在一个大型软件项目中进行协作,但我在尝试实现一个不错的功能时遇到了问题。
问题是,我不知道如何自动滚动到某个用户可以选择的特定项目。包装面板用作项目控件中的项目面板模板。
为了更好地理解以下代码:
<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/