none
DataTrigger is not working

    Question

  • I am trying to create a generic style for textblocks that shows negative numeric values in red.  I was able to create a style that works with infragistics controls but I am unable to create a style that works with a textblock.

    The following works fine:

    <Style TargetType="{x:Type igEditors:XamNumericEditor}" x:Key="ShortNumericStyle">
            <Style.Triggers>
                <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Value, 
                                Converter={StaticResource IsNegative}}" Value="True">
                    <Setter Property="Foreground" Value="Red"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    


    The following does not work:

    <Style TargetType="{x:Type TextBlock}" x:Key="TextBlockNumberStyle">
            <Style.Triggers>
                <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Text,
                                Converter={StaticResource IsNegative}}" Value="True">
                    <Setter Property="Foreground" Value="Red"/>
                </DataTrigger>
            </Style.Triggers>
            <Setter Property="HorizontalAlignment" Value="Right"></Setter>
        </Style>
    

    Here is the host page:

    The following works:

    <igEditors:XamNumericEditor Value="{Binding /USD_Accrued_Int, Mode=TwoWay}" Style="{StaticResource ShortNumericStyle}">
                        
                    </igEditors:XamNumericEditor>
    


    The following does not work:


     

    <TextBlock Text="{Binding /Dirty_Price, Mode=TwoWay, Converter={StaticResource NumberFormatConverter}, ConverterParameter='#,0.00'}" Style="{StaticResource TextBlockNumberStyle}"></TextBlock>
    


     

     

    By the way I did read this post however I am defining my styles in an application-level resource dictionary so I am unable to bind to a data element property name as is shown in the answer to the post.

     

     

     

     

    Monday, November 28, 2011 11:18 PM

Answers

  • If you manually set

            <TextBlock Text="True" 
                       Style="{StaticResource TextBlockNumberStyle}"></TextBlock>

    and

    <Style.Triggers>
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Text}" Value="True">

    then you will know that the DataTrigger does really work.  So the problem could be inside the converter:

    Converter={StaticResource IsNegative}
    

    Could you please post the code for this converter?

     

     

     


    Need translation help? I translate from English to Japanese and vice versa. Please feel free to contact me for your translation needs. 日英・英日翻訳依頼を受け付けています。 お気軽にご相談下さい。(Ldiary.com)
    • Marked as answer by SWheaties Tuesday, November 29, 2011 12:34 AM
    Monday, November 28, 2011 11:33 PM

All replies

  • If you manually set

            <TextBlock Text="True" 
                       Style="{StaticResource TextBlockNumberStyle}"></TextBlock>

    and

    <Style.Triggers>
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Text}" Value="True">

    then you will know that the DataTrigger does really work.  So the problem could be inside the converter:

    Converter={StaticResource IsNegative}
    

    Could you please post the code for this converter?

     

     

     


    Need translation help? I translate from English to Japanese and vice versa. Please feel free to contact me for your translation needs. 日英・英日翻訳依頼を受け付けています。 お気軽にご相談下さい。(Ldiary.com)
    • Marked as answer by SWheaties Tuesday, November 29, 2011 12:34 AM
    Monday, November 28, 2011 11:33 PM
  • Thank you Ldiary.  The converter was failing because negative values were enclosed by parenthisis.

     

    Tuesday, November 29, 2011 12:33 AM