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

查看:169
本文介绍了使用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.

任何帮助?

编辑:
好​​的,Steve Robbins的答案对控制问题。

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天全站免登陆