使用 ComboBox 控制 TabControl 活动选项卡 [英] Controlling the TabControl active tab with a ComboBox

查看:29
本文介绍了使用 ComboBox 控制 TabControl 活动选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真正想要实现的是通过使用组合框作为导航控件来完全控制活动的 TabItem.

What i am really trying to achieve is to full control the active TabItem by using the combobox as the navigation control.

这是我目前得到的:

    <TabControl Canvas.Left="26" Canvas.Top="27" Height="100" Name="TabControl1" Width="220">
        <TabItem Header="TabItem1" x:Name="TabItem1">
            <Grid />
        </TabItem>
        <TabItem Header="TabItem2" x:Name="TabItem2">
            <Grid />
        </TabItem>
    </TabControl>


    <ComboBox Canvas.Left="126" Canvas.Top="134" Height="23" Name="CmbTabs" Width="120" 
              ItemsSource="{Binding ElementName=TabControl1, Path=Items}" 
              SelectedValue="{Binding ElementName=TabControl1, Path=SelectedIndex}" 
              SelectedValuePath="TabIndex"
              DisplayMemberPath="Header"/>

仍然唯一真正起作用的是当我按下组合框的切换按钮时显示的列表.即使通过列表选择 tabitem 名称也没有任何作用,它甚至不会更新组合框的选定值文本框.

Still the only thing that actual works is the list that shows up when i press the togglebutton of the combobox. Even selecting a tabitem name through the list does not do anything, it does not even update the selected value textbox of the combobox.

有什么帮助吗?

好吧,史蒂夫罗宾斯的回答对控制"问题很有效.

Ok the answer of Steve Robbins worked fine for the "controling" issue.

在组合框下拉列表中选择一个项目不会更新组合框的值怎么办?(组合框文本框仍然是空白的!!)

What about the fact that selecting an item in the combobox drop down list does not update the value of the combobox? (the comboboxes textbox is still blank!!)

推荐答案

如果您尝试从 Combo 控制 TabControl 那么它看起来有点倒退我..如果您将选项卡控件上的 SelectedIndex 更改为绑定它应该可以工作的组合:

If you're trying to control the TabControl from the Combo then it looks a bit backwards to me.. if you change the SelectedIndex on the tab control to bind it to the combo it should work:

<TabControl Canvas.Left="26" Canvas.Top="27" Height="100" Name="TabControl1" Width="220" SelectedIndex="{Binding ElementName=CmbTabs, Path=SelectedIndex}">
        <TabItem Header="TabItem1" x:Name="TabItem1">
            <Grid />
        </TabItem>
        <TabItem Header="TabItem2" x:Name="TabItem2">
            <Grid />
        </TabItem>
    </TabControl>

这篇关于使用 ComboBox 控制 TabControl 活动选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆