This is a migrated thread and some comments may be shown as answers.

Problems with DataTemplateRule

1 Answer 62 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bradley
Top achievements
Rank 1
Bradley asked on 08 Dec 2011, 11:50 PM
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

1 Answer, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 13 Dec 2011, 01:59 PM
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 >>

Tags
GridView
Asked by
Bradley
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Share this question
or