We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Trying to set a cell a specific color based upon data value and getting an error.

Thread ID:

Created:

Updated:

Platform:

Replies:

124721 Jun 24,2016 03:37 PM UTC Jun 30,2016 05:14 AM UTC UWP 3
loading
Tags: SfDataGrid
Garling Beard
Asked On June 24, 2016 03:37 PM UTC

I am using the following code to check a value and set a cell a specific color:

<Application.Resources>

        <DataTemplate x:Key="CellTemplate1">
            <TextBlock Foreground="DarkBlue" Text="{Binding Path=Value}" />
        </DataTemplate>

        <DataTemplate x:Key="CellTemplate2">
            <TextBlock Foreground="DarkRed" Text="{Binding Path=Value}" />
        </DataTemplate>

    </Application.Resources>

    <Page.Resources>
        <local:CellTemplateSelector x:Key="cellTemplateSelector" />
    </Page.Resources>

c#
public class CellTemplateSelector : DataTemplateSelector
        {
            protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
            {
                if (item != null)
                {
                    var data = (item as DataContextHelper).Record as orderHeader;

                    if (data.ORDERSTATUS == "0")
                        return Application.Current.Resources["CellTemplate1"] as DataTemplate;

                    else
                        return Application.Current.Resources["CellTemplate2"] as DataTemplate;
                }

                return base.SelectTemplateCore(item, container);
            }
        }

I am getting an error on <Application.Resources> - The member "Resources" is not recognized or is not accessible" and on <local:CellTemplateSelector x:Key="cellTemplateSelector" /> The name "CellTemplateSelector" does not exist in the namespace "using:HDW_Order" 

I am also attaching the xaml file

Attachment: custDetails_d504a4d7.zip

Elavarasan M [Syncfusion]
Replied On June 27, 2016 10:55 AM UTC

Hi Garling, 

Thank you for contacting Syncfusion support. 

We have analyzed your query and prepared the sample based on your code, its working in our side without any exception and able to set the custom templates using CellTemplateSelector like below code example, 

<Application.Resources> 
    <DataTemplate x:Key="CellTemplate1"> 
        <TextBlock Foreground="DarkBlue" Text="{Binding Path=Value}" /> 
    </DataTemplate> 
 
    <DataTemplate x:Key="CellTemplate2"> 
        <TextBlock Foreground="DarkRed" Text="{Binding Path=Value}" /> 
    </DataTemplate> 
</Application.Resources> 
 
<Page.Resources> 
        <local:CellTemplateSelector x:Key="templateSelector"/> 
</Page.Resources> 
 
<syncfusion:GridTextColumn CellTemplateSelector="{StaticResource templateSelector}" ColumnSizer="SizeToHeader" TextWrapping="NoWrap"  HeaderText="OrderID" MappingName="OrderID" SetCellBoundValue="True" /> 

public class CellTemplateSelector : DataTemplateSelector 
{ 
    protected override DataTemplate SelectTemplateCore(object item, DependencyObject container) 
    { 
        if (item != null) 
        { 
            var data = (item as DataContextHelper).Record as OrderInfo; 
 
            if (data.OrderID < 1005) 
                return Application.Current.Resources["CellTemplate1"] as DataTemplate; 
 
            else 
                return Application.Current.Resources["CellTemplate2"] as DataTemplate; 
        } 
 
        return base.SelectTemplateCore(item, container); 
    } 
} 


 
 
Note: We suspect that you are created the TemplateSelector in another namespace. Could you please ensure whether the TemplateSelector is present in “HDW_Order” namespace, according to your code. 

You can refer the below UG to know more about the TemplateSelectors, 

 
Regards, 
Elavarasan M

Garling Beard
Replied On June 29, 2016 01:24 PM UTC

Thank you, I have it working now. 

Elavarasan M [Syncfusion]
Replied On June 30, 2016 05:14 AM UTC

Hi Garling, 

Thanks for your update. 

Regards, 
Elavarasan M

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;