Change Row Background

2 posts, 0 answers
  1. WILLIAM
    WILLIAM avatar
    134 posts
    Member since:
    Jun 2012

    Posted 05 May 2014 Link to this post

    I have read most of threads dealing with trying to change the row color.  I have also looked at the demo.  I have the converter and selector setup in my code behind.  The rules are working, and the selector is choosing the correct style when looping through the rules.  However, I keep getting xaml markup errors when the view is being displayed.  Can you tell me what's wrong?  This seems so simple, yet I don't see a problem.

    XAML:
    <Grid.Resources>
     
        <Style x:Key="ScheduledCallWorkedStyle"
               TargetType="telerik:GridViewRow">
            <Setter Property="Background" Value="BlanchedAlmond" />
        </Style>
     
        <Style x:Key="ScheduledCallNotWorkedStyle"
               TargetType="telerik:GridViewRow">
            <Setter Property="Background" Value="Green" />
        </Style>
     
        <ViewModels:ScheduledCallWorkedConverter x:Key="ScheduledCallWorkedConverter" />
     
        <ViewModels:ScheduledCallWorkedStyleSelector x:Key="ScheduledCallWorkedSelector"  ConditionConverter="{StaticResource ScheduledCallWorkedConverter}">
            <ViewModels:ScheduledCallWorkedStyleSelector.Rules>
                <ViewModels:ScheduledCallWorkedStyleRule Style="{StaticResource ScheduledCallWorkedStyle}" >
                    <ViewModels:ScheduledCallWorkedStyleRule.Value>
                        <sys:Boolean>True</sys:Boolean>
                    </ViewModels:ScheduledCallWorkedStyleRule.Value>
                </ViewModels:ScheduledCallWorkedStyleRule>
                <ViewModels:ScheduledCallWorkedStyleRule Style="{StaticResource ScheduledCallNotWorkedStyle}" >
                    <ViewModels:ScheduledCallWorkedStyleRule.Value>
                        <sys:Boolean>False</sys:Boolean>
                    </ViewModels:ScheduledCallWorkedStyleRule.Value>
                </ViewModels:ScheduledCallWorkedStyleRule>
            </ViewModels:ScheduledCallWorkedStyleSelector.Rules>
        </ViewModels:ScheduledCallWorkedStyleSelector>
     
    </Grid.Resources>
     
     
    <telerik:RadGridView
        Grid.Row="1" 
        Name="uxScheduledCalls"
        ItemsSource="{Binding ElementName=uxCollectionNavigator, Path=CollectionView}"
        SelectedItem="{Binding ElementName=uxCollectionNavigator, Path=CollectionView}"
        RowDetailsStyleSelector="{StaticResource ScheduledCallWorkedSelector}"
        CanUserDeleteRows="False"
        cal:Message.Attach="[Event KeyUp] = [Action KeyUp($source, $eventArgs)]" >
        <telerik:RadContextMenu.ContextMenu>
            <telerik:RadContextMenu Name="uxScheduledCallsContextMenu"/>
        </telerik:RadContextMenu.ContextMenu>
    </telerik:RadGridView>

    Code Behind:
    public class ScheduledCallWorkedConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var sclep = value as ScheduledCallLogEntryProjection;
            if (sclep == null) return false;
     
            return (DateTime.Now - sclep.CallLogEntryLastModDttm).TotalHours <= 24;
        }
     
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
     
    public class ScheduledCallWorkedStyleSelector : StyleSelector
    {
        public override Style SelectStyle(object item, DependencyObject container)
        {
            var conditionValue = ConditionConverter.Convert(item, null, null, null);
     
            foreach (var rule in Rules)
            {
                if (Equals(rule.Value, conditionValue))
                {
                    return null;
                }
            }
     
            return null;
        }
         
        List<ScheduledCallWorkedStyleRule> _rules;
        public List<ScheduledCallWorkedStyleRule> Rules
        {
            get { return _rules ?? (_rules = new List<ScheduledCallWorkedStyleRule>()); }
        }
     
        public IValueConverter ConditionConverter { get; set; }
    }
     
    public class ScheduledCallWorkedStyleRule
    {
        public bool Value { get; set; }
     
        public Style Style { get; set; }
    }
  2. WILLIAM
    WILLIAM avatar
    134 posts
    Member since:
    Jun 2012

    Posted 06 May 2014 Link to this post

    I found this article which fixed my issue.

    Thanks!!
  3. DevCraft banner
Back to Top