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

Change Row Background

1 Answer 10 Views
GridView
This is a migrated thread and some comments may be shown as answers.
WILLIAM
Top achievements
Rank 1
WILLIAM asked on 05 May 2014, 06:29 PM
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; }
}

1 Answer, 1 is accepted

Sort by
0
WILLIAM
Top achievements
Rank 1
answered on 06 May 2014, 01:41 PM
I found this article which fixed my issue.

Thanks!!
Tags
GridView
Asked by
WILLIAM
Top achievements
Rank 1
Answers by
WILLIAM
Top achievements
Rank 1
Share this question
or