C# 如何自动滚动到包装中的特定项目?
目前我在一个大型软件项目中进行合作,我试图实现的一个很好的功能遇到了问题 问题是,我不知道如何自动滚动到某个用户可以选择的特定项目。wrappanel用作itemscontrol中的itemspaneltemplate 为了更好地理解,代码如下所示:C# 如何自动滚动到包装中的特定项目?,c#,scroll,wrappanel,C#,Scroll,Wrappanel,目前我在一个大型软件项目中进行合作,我试图实现的一个很好的功能遇到了问题 问题是,我不知道如何自动滚动到某个用户可以选择的特定项目。wrappanel用作itemscontrol中的itemspaneltemplate 为了更好地理解,代码如下所示: <ItemsControl ItemsSource="{Binding SomeData}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate>
<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派生的控件都有一个方法将列表框/数据网格滚动到当前选定的项
例如:
listBox1.ScrollIntoView(listBox1.SelectedIndex);
或
这里有另一个解决方案
更新:
带包装的列表框
<ListBox x:Name="myList">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel ItemHeight="150" ItemWidth="150"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</Listbox>
很抱歉我的解释不好,我的问题不是我无法设置焦点。我的问题是自动滚动到所选项目,以便显示。列表比显示器长,现在你必须手动滚动。是的,类似scrollintoview的方法正是我需要的,但是wrappanel没有这样的方法。我可以使用哪些包装纸替代品??在itemscontrol中??我不太确定您想要做什么,但是为什么不在列表框中放置一个wrappanel而不是itemscontrol呢?给我的回答增加了一个例子对不起,这是我的错。我不知道listbox是itemscontrol的替代品。谢谢你的帮助,这正是我需要的。
<ListBox x:Name="myList">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel ItemHeight="150" ItemWidth="150"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</Listbox>