Home > Software engineering >  Change controls properties outside Tabcontrol based on selected Tab
Change controls properties outside Tabcontrol based on selected Tab

Time:11-25

I am working with tabcontrol in WPF. I want a button outside the tabcontrol to change to a dropdownbutton (combobox) based on certain choices(tab page selected) Appreciate your help.

CodePudding user response:

Add both controls to your layout and toggle their visibility based on a datatrigger and the selectedindex of the tabcontrol

    <ComboBox>
        <ComboBox.Style>
            <Style TargetType="ComboBox">
                <Setter Property="Visibility" Value="Collapsed"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding ElementName=yourTabControl, Path=SelectedIndex}" Value="0">
                        <Setter Property="Visibility" Value="Visible"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </ComboBox.Style>
    </ComboBox>
    <Button>
        <Button.Style>
            <Style TargetType="Button">
                <Setter Property="Visibility" Value="Visible"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding ElementName=yourTabControl, Path=SelectedIndex}" Value="1">
                        <Setter Property="Visibility" Value="Collapsed"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Button.Style>
    </Button>
  • Related