在列表视图中显示打开的选项卡项名称
我正在尝试在列表视图或列表框中显示打开的选项卡名称列表(建议?)。
经历了不同类型的绑定选项,我能够绑定到单个选项卡名称,但它显示垂直而不是水平。这是我的 XAML:
<ListView DockPanel.Dock="Left"
Height="352"
Name="listView1"
Width="132"
ItemsSource="{Binding ElementName=RulesTab, Path=Name}"
IsSynchronizedWithCurrentItem="True"
FlowDirection="LeftToRight"
HorizontalAlignment="Left"
HorizontalContentAlignment="Left"
DataContext="{Binding}">
任何指针都将不胜感激,因为我希望能够看到所有打开的选项卡的列表,然后双击其中一个选项卡以使该选项卡成为焦点。非常感谢!
I'm trying to display a list of open tab names in a listview or listbox (recommendations?).
Been going through the different type of binding options and I'm able to bind to a single tab name but it displays vertical instead of horizontal. Here is my XAML:
<ListView DockPanel.Dock="Left"
Height="352"
Name="listView1"
Width="132"
ItemsSource="{Binding ElementName=RulesTab, Path=Name}"
IsSynchronizedWithCurrentItem="True"
FlowDirection="LeftToRight"
HorizontalAlignment="Left"
HorizontalContentAlignment="Left"
DataContext="{Binding}">
Any pointers would be greatly appreciated as I'd like to be able to see a list of all the tabs open and then double click on one to bring the tab into focus. Many thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
下面是
TabControl
和ListBox
的示例,显示其中TabItems
的名称:下面是背后的代码:
编辑以添加双击行为。
Here is an example of a
TabControl
and aListBox
showing the names of theTabItems
that are in it:and here's the code behind:
Edited to add double-click behavior.
如何使用列表视图枚举选项卡控件中的选项卡的简化示例:
Simplified example how to enumerate the tabs in a tab control with a listview:
我仍然不确定你到底想要什么,无论如何,如果需要的话可以调整。
首先,如果您绑定到特定项目,您将始终拥有一个项目,您需要将
ItemsSource
设置为集合。假设您想要列表中所有选项卡的名称或标题,您可以将选项卡控件的
Items
设置为ItemsSource
,然后应用ItemTemplate,一些示例代码:
如果您不使用
ItemTemplate
,您将收到错误,因为同一项目只能是一个父项的可视子项。坦率地说,这似乎有点毫无意义,因为它只是重申您的选项卡,我是否误解了什么?如果是这样,请进一步澄清。
编辑:哦哈哈,三个几乎相同的答案......
I'm still unsure as to what exactly you want, anyway, this can be adjusted if needed.
First of all if you bind to a specific item you will always have one item, you need to set
ItemsSource
to a collection.Assuming you want to have the names or headers of all the tabs in your list you can set the tab control's
Items
as theItemsSource
and then apply aItemTemplate
, some example code:If you do not use the
ItemTemplate
you'll get an error because the same item can only be a visual child of one parent.Frankly this seems a bit pointless since it just reiterates your tabs, did i misunderstand something? If so please clarify further.
Edit: Oh lol, three almost identical answers...