0

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>
Anatoliy Nikolaev
  • 22,370
  • 15
  • 69
  • 68
Relativity
  • 6,690
  • 22
  • 78
  • 128

3 Answers3

4

Oh, it is working as expected, however that probably is not what you expected. The key is dependency property precedence. The "local values" (set in the element tag) override everything a style tries to do. You need to extract such properties to a style setter which has a lower precedence than a style trigger.

H.B.
  • 166,899
  • 29
  • 327
  • 400
2

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>
Anthony
  • 155
  • 2
  • 13
  • @Relativity: (That is because he silently removed his error within five minutes of submitting the answer, which by the way was after mine) – H.B. Dec 12 '11 at 21:00
  • I can't quickly answer questions in English... this is why I've pasted this code and typed some words a little bit later.... – Anthony Dec 12 '11 at 21:09
  • to err is human...i saw that error - you mean -> " Visibility="Collapsed" ...right. But I got the solution out of it. – Relativity Dec 12 '11 at 21:39
0

Are you expecting an OR or AND to be applied between the conditions. You are only going to get AND. If you want and OR just add another public property the is the OR of the the two.

Represents a trigger that applies property values or performs actions when the bound data meet a set of conditions. http://msdn.microsoft.com/en-us/library/system.windows.multidatatrigger.aspx

paparazzo
  • 44,497
  • 23
  • 105
  • 176