WPF SHOWING / HIDING A CONTROL WITH TRIGGERS

marcel ethan

Total Post:105

Points:735
Posted by  marcel ethan
WPF 
WPF
 2221  View(s)
Ratings:
Rate this:
Hi experts!

I am trying to create xaml logic to show / hide a control based on the value of the AllowMiscTitle on the ViewModel. The xaml consist of two fields a combobox of the standard tiles ("Mr", "Mrs", ..., "Other") when "Other" is selected I want the textbox to display.

I've created the follow xaml:

                <DockPanel Validation.Error="Validation_Error" HorizontalAlignment="Stretch">

                <ComboBox ItemsSource="{Binding Path=Titles, Mode=OneTime}"

                      Text="{Binding Path=Title}"/>

                <TextBox x:Name="TxtBxTitle" Margin="5,5" Visibility="Visible">

                    <TextBox.Style>

                        <Style>

                            <Style.Triggers>

                                <DataTrigger Binding="{Binding Path=AllowMiscTitle}" Value="false">

                                    <Setter Property="TextBox.Visibility" Value="Hidden"/>

                                </DataTrigger>

                            </Style.Triggers>

                        </Style>

                    </TextBox.Style>

                </TextBox>

            </DockPanel>

thanks in advance

  1. shreesh chandra shukla

    Post:105

    Points:735
    Re: WPF Showing / Hiding a control with triggers

    Solution!

    That trigger won't work because you set Visibility explicitly in TextBox

    try this..

    <TextBox x:Name="TxtBxTitle" Margin="5,5">

                    <TextBox.Style>

                        <Style>

                            <Style.Triggers>

                                <DataTrigger Binding="{Binding Path=AllowMiscTitle}" Value="false">

                                    <Setter Property="TextBox.Visibility" Value="Hidden"/>

                                </DataTrigger>

                            </Style.Triggers>

                        </Style>

                    </TextBox.Style>

                </TextBox>

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!