Problems with DataTemplateRule

2 posts, 0 answers
  1. Bradley
    Bradley avatar
    16 posts
    Member since:
    Aug 2010

    Posted 08 Dec 2011 Link to this post

    In my GridView I have a column being bound to MyValue.  There's 5 different "ranges" MyValue can fall into, and depending on what it is the background changes colors.

    The ranges are as follows: >= 8, >= 4 && < 8, >= -4 && < 4, >= -8 && < -4, and finally < 8.

    Here's my current code, though I've tried many different iterations of this trying to get it to work.

                  <telerik:GridViewDataColumn Header="MyValue" DataMemberBinding="{Binding MyValue}">
                        <telerik:GridViewDataColumn.CellTemplateSelector>
                            <telerik:ConditionalDataTemplateSelector>
                                <telerik:DataTemplateRule Condition="MyValue >= 8">
                                    <DataTemplate>
                                        <Border Background="Red" BorderBrush="Black" BorderThickness="1">
                                            <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding MyValue}" Foreground="White" />
                                        </Border>
                                    </DataTemplate>
                                </telerik:DataTemplateRule>
                                <telerik:DataTemplateRule Condition="MyValue >= 4">
                                    <DataTemplate>
                                        <Border Background="Yellow" BorderBrush="Black" BorderThickness="1">
                                            <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding MyValue}" Foreground="Black" />
                                        </Border>
                                    </DataTemplate>
                                </telerik:DataTemplateRule>
                                <telerik:DataTemplateRule Condition="MyValue >= (4)">
                                    <DataTemplate>
                                        <Border Background="Green" BorderBrush="Black" BorderThickness="1">
                                            <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding MyValue}" Foreground="White" />
                                        </Border>
                                    </DataTemplate>
                                </telerik:DataTemplateRule>
                                <telerik:DataTemplateRule Condition="MyValue >= (8)">
                                    <DataTemplate>
                                        <Border Background="Yellow" BorderBrush="Black" BorderThickness="1">
                                            <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding MyValue}" Foreground="Black" />
                                        </Border>
                                    </DataTemplate>
                                </telerik:DataTemplateRule>
                                <telerik:DataTemplateRule Condition="MyValue &lt; (8)">
                                    <DataTemplate>
                                        <Border Background="Red" BorderBrush="Black" BorderThickness="1">
                                            <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Text="{Binding MyValue}" Foreground="White" />
                                        </Border>
                                    </DataTemplate>
                                </telerik:DataTemplateRule>                            
                            </telerik:ConditionalDataTemplateSelector>
                        </telerik:GridViewDataColumn.CellTemplateSelector>
                    </telerik:GridViewDataColumn>

    In this version you can see I tried doing negatives as (N), but I've also tried -N and that didn't work at all.  What's happening is that only some of the rules are working, and the -4 to 4 rule never works, the background is never green.  It's almost always red, and sometimes it'll turn yellow, but only for the 4 to 8 range, never for the -8 to -4 range.  Any ideas what I'm doing wrong?  Thanks
  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 13 Dec 2011 Link to this post

    Hi Bradley,

    Please try the following syntax MyValue >= (-8)
    Let me know in case this does not do the trick .

    Regards,
    Pavel Pavlov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top