I need compare with a variable external from CellTemplateSelector

2 posts, 0 answers
  1. Jones
    Jones avatar
    5 posts
    Member since:
    May 2017

    Posted 05 Jul Link to this post

    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.

  2. Polya
    Admin
    Polya avatar
    238 posts

    Posted 10 Jul Link to this post

    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.
Back to Top