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

I need compare with a variable external from CellTemplateSelector

1 Answer 45 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
Jones
Top achievements
Rank 1
Jones asked on 05 Jul 2017, 03:30 PM

Hi mates, i have a variable from database, it's the comparable flag to set a DataTemplate to my PivotGrid.

 

public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            var cellAggregate = item as CellAggregateValue;
            if (cellAggregate != null)
            {
                var description = cellAggregate.Description as PropertyAggregateDescription;
                var test = item as PlannedRouteByMonthToGridPivot;

                if (description.PropertyName == nameof(ViewModels.PlannedRouteByMonthToGridPivot.PercentExecuted))
                {
                    
                    if (System.Convert.ToDouble(cellAggregate.Value) >= 0.965d)
                    {
                        return this.GreenTemplate;
                    }
                    else
                    {
                        return this.RedTemplate;
                    }
                }
            }

            return base.SelectTemplate(item, container);
        }

 

I need replace the number 0.965d with a variable in my RadPivotGrid DataProvider, someone have any ideia how i can do it.

1 Answer, 1 is accepted

Sort by
0
Polya
Telerik team
answered on 10 Jul 2017, 01:00 PM
Hello Jones,

In order to have the DataProvider in your RadPivotGrid.CellTemplateSelector I suggest adding an additional property in the selector which will hold a reference to the DataProvider:
public DataProviderBase DataProvider { get; set;}

And after InitializeComponent you can assign the DataProvider instance to that property in the code behind the following way:
var cellTemplateSelector = this.Resources["CellTemplateSelector"] as CellTemplateSelector;
 
var dataProvider = this.Resources["DataProvider"] as DataProviderBase;
 
cellTemplateSelector.DataProvider = dataProvider;


This way you will have a reference to the DataProvider in the selector.

Hope this helps.

Regards,
Polya
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
PivotGrid
Asked by
Jones
Top achievements
Rank 1
Answers by
Polya
Telerik team
Share this question
or