WPF Visibility of a UI element based on combo selection

Posted by tim on Stack Overflow See other posts from Stack Overflow or by tim
Published on 2010-04-01T16:08:28Z Indexed on 2010/04/01 16:13 UTC
Read the original article Hit count: 420

Filed under:
|
|

Trying to show a label only when a certain item in a combo is selected. Code should pretty much explain it.

    <ComboBox Name="comboMyCombo">
        <ComboBoxItem>Don't show the label</ComboBoxItem>
        <ComboBoxItem>Show the label</ComboBoxItem>
    </ComboBox>

    <Label Visibility="Collapsed">This is my label
        <Label.Style>
            <Style>
                <Style.Triggers>
                    <DataTrigger 
                            Binding="{Binding ElementName=comboMyCombo, Path=SelectedValue}" Value="Show the label">
                        <Setter Property="Label.Visibility" Value="Visible"></Setter>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </Label.Style>
    </Label>

© Stack Overflow or respective owner

Related posts about visibility

Related posts about combobox