wpfvisibilitytextblockmultitriggermultidatatrigger

How to settle textblock visibility as collapsed by default...and toggle based on conditions?


I have a TextBlock - which is collapsed by default and will be visible only when it meet two conditions.

I have the below XAML for same. But it is not working as expected.

Any help would be appreciated. thanks

<TextBlock Text="{Binding Path=CC.Name}" VerticalAlignment="Center"  FontWeight="Bold" Margin="0,0,10,0"  Visibility="Collapsed">
    <TextBlock.Style>
        <Style>
            <Style.Triggers>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>                                
                        <Condition Binding="{Binding Path=IsP}" Value="True" />    
                            <Condition Binding="{Binding Path=IsC}" Value="True" />
                        </MultiDataTrigger.Conditions>

                        <Setter Property="TextBlock.Visibility" Value="Visible"/>

                    </MultiDataTrigger>                           
            </Style.Triggers>
        </Style>
    </TextBlock.Style>
</TextBlock>

Solution

  • you have to use this setter:

    <TextBlock Text="{Binding Path=CC.Name}" VerticalAlignment="Center"  FontWeight="Bold" Margin="0,0,10,0">
        <TextBlock.Style>
            <Style>
               <Setter Property="TextBlock.Visibility" Value="Collapsed"/>
               <Style.Triggers>
                   <MultiDataTrigger>
                        ...
                   </MultiDataTrigger>                           
               </Style.Triggers>
           </Style>
         </TextBlock.Style>
    </TextBlock>