This question is locked. New answers and comments are not allowed.
I've looked at several examples (see links below), my code compiles and runs fine, except that my page loads initially with no data, then goes blank after a few seconds. What's wrong? I know it's to do with my Style Selector, but I can't find any problem even after debugging the SelectStyle method.
C# Code for the Custom Style Selector
Method 1
- using a Custom Style Selector
Method 2
- using a Custom Style Selector as a Static Resource
Method 3
- using a data template and dynamically binding the background)
- this works, but there's ugly padding around the label
Any ideas why the style selector is causing the page to go blank? I've debugged and got no exceptions.
Reference links:
Method 1: http://csharping.com/binding/binding-the-background-color-of-a-radgridview-cell/
Method 2: http://blogs.telerik.com/blogs/posts/10-04-01/conditional_styles_and_templates_with_radgridview_for_silverlight_and_wpf.aspx
Method 3: http://www.telerik.com/community/forums/wpf/gridview/binding-background-of-a-cell.aspx
Cheers,
Lindsay
C# Code for the Custom Style Selector
using System.Windows;using System.Windows.Media;using Telerik.Windows.Controls;using Telerik.Windows.Controls.GridView;namespace AzureDashboard.Class{ public class PercentAttainmentStyleSelector : StyleSelector { public override Style SelectStyle(object item, DependencyObject container) { var style = new Style(typeof(GridViewRow)); var cell = (GridViewCell)container; ChartDataContainer rowData = (ChartDataContainer)item; if (rowData.Decimal1 > (decimal)0.8) { style.Setters.Add(new Setter(GridViewCell.BackgroundProperty, new SolidColorBrush(Colors.Yellow))); } else { style.Setters.Add(new Setter(GridViewCell.BackgroundProperty, new SolidColorBrush(Colors.Red))); } return style; } }}Method 1
- using a Custom Style Selector
<telerik:GridViewDataColumn Width="100" DataMemberBinding="{Binding Decimal1}" DataFormatString="#0%" IsGroupable="False" IsFilterable="False"> <telerik:GridViewDataColumn.Header> <Grid> <TextBlock Text="Cumulative YTD Attainment" TextWrapping="Wrap"/> </Grid> </telerik:GridViewDataColumn.Header> <telerik:GridViewDataColumn.CellStyleSelector> <local:PercentAttainmentStyleSelector></local:PercentAttainmentStyleSelector> </telerik:GridViewDataColumn.CellStyleSelector>Method 2
- using a Custom Style Selector as a Static Resource
<Grid x:Name="LayoutRoot" HorizontalAlignment="Left"> <Grid.Resources> <local:PercentAttainmentStyleSelector x:Key="MyPercentAttainmentStyleSelector" /> </Grid.Resources><telerik:GridViewDataColumn Width="100" DataMemberBinding="{Binding Decimal1}" CellStyleSelector="{StaticResource MyPercentAttainmentStyleSelector}" DataFormatString="#0%" IsGroupable="False" IsFilterable="False"> <telerik:GridViewDataColumn.Header> <Grid> <TextBlock Text="Cumulative YTD Attainment" TextWrapping="Wrap"/> </Grid> </telerik:GridViewDataColumn.Header> </telerik:GridViewDataColumn>Method 3
- using a data template and dynamically binding the background)
- this works, but there's ugly padding around the label
<telerik:GridViewDataColumn Width="100" DataFormatString="#0%" IsGroupable="False" IsFilterable="False"> <telerik:GridViewDataColumn.Header> <Grid> <TextBlock Text="Cumulative YTD Attainment" TextWrapping="Wrap"/> </Grid> </telerik:GridViewDataColumn.Header> <telerik:GridViewDataColumn.CellTemplate> <DataTemplate> <sdk:Label Padding="0" Height="30" Width="105" Content="{Binding Decimal1}" Background="{Binding BackgroundBrush}" Margin="0" /> </DataTemplate> </telerik:GridViewDataColumn.CellTemplate>Any ideas why the style selector is causing the page to go blank? I've debugged and got no exceptions.
Reference links:
Method 1: http://csharping.com/binding/binding-the-background-color-of-a-radgridview-cell/
Method 2: http://blogs.telerik.com/blogs/posts/10-04-01/conditional_styles_and_templates_with_radgridview_for_silverlight_and_wpf.aspx
Method 3: http://www.telerik.com/community/forums/wpf/gridview/binding-background-of-a-cell.aspx
Cheers,
Lindsay