Home > DeveloperSection > Forums > WPF Showing / Hiding a control with triggers
marcel ethan
marcel ethan

Total Post:105

Points:735
Posted on    July-18-2013 2:24 AM

 WPF WPF 
Ratings:


 1 Reply(s)
 1529  View(s)
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



shreesh chandra shukla
shreesh chandra shukla

Total Post:105

Points:735
Posted on    July-18-2013 2:35 AM

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>


Don't want to miss updates? Please click the below button!

Follow MindStick