How to bind a property which is in the collection to RadPivotgrid CellTemplate

5 posts, 0 answers
  1. Ramya
    Ramya avatar
    15 posts
    Member since:
    Dec 2013

    Posted 01 Jun 2014 Link to this post

    Hi Team,

    Thank you for your continuous support.I have the urgent issue with the Rad Pivot Grid,Please help me out.

    Here is the Scenario,I have the Rad Pivot Grid Cell Template Where a Text block is placed i need to set the foreground based on the condition,have used multi binding for it, i need to pass few parameters which are in the collection which is bound to the item source of data provider,how can i access those objects in order to bind it to the foreground, i have browsed for it , where we only bind the data as Text="{Binding Data}",but could not bind any property which is in the collection.How can i do this....
      <DataTemplate x:Key="CellTemplate">
                <TextBlock Margin="6" VerticalAlignment="Center" HorizontalAlignment="Right"  Text="{Binding Data,Mode=OneWay,Converter={StaticResource PpcConverter}}"  FontSize="{Binding Path=FontSize,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type pivot:RadPivotGrid}}}">
                    <TextBlock.Foreground>
                        <MultiBinding Converter="{StaticResource MultiConverter}" >
                            <Binding Path="Data" Mode="OneWay"/>
                            <Binding Path="Product1"/>
                            <Binding Path="Product2" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type pivot:RadPivotGrid}}"></Binding>
                                                 
                        </MultiBinding>
                    </TextBlock.Foreground>
                </TextBlock>
            </DataTemplate>

    Many Thanks,
    Ruth
  2. Kalin
    Admin
    Kalin avatar
    1208 posts

    Posted 02 Jun 2014 Link to this post

    Hello Ramya,

    The PivotGrid is designed to display calculated values of the data in the ItemsSource, not the data itself. So one cell might represent the aggregated value of 10-15 records from the ItemsSource. In the CellTemplateSelector you can get different information about the cell (row, column, parent cells, PropertyAggregateDescription name) and depending on them to change the Foreground color of the TextBlock as required.

    Hope this helps.

    Regards,
    Kalin
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Ramya
    Ramya avatar
    15 posts
    Member since:
    Dec 2013

    Posted 02 Jun 2014 in reply to Kalin Link to this post

    Hi Kalin,
    Thankyou for your post,but i need to bind the foreground the properties which has been used in the collection which bound to the itemsource,is there anyway to achieve it?

    Thanks,
    Ruth
  5. Ramya
    Ramya avatar
    15 posts
    Member since:
    Dec 2013

    Posted 02 Jun 2014 in reply to Ramya Link to this post

    Hi ,

    It means the properties are there in the itemsource of pivot grid but need to access those in the celltemplate and they are not part of column or row group descriptions
  6. Kalin
    Admin
    Kalin avatar
    1208 posts

    Posted 03 Jun 2014 Link to this post

    Hello Ramya,

    I understand the requirement and the only solution I can suggest would be using the same MultiValueConverter to pass the collection in the ViewModel as well as the Data displayed in the cell. This way will have the underlying collection in the converter and depending on the value of the Data you can return the desired colors. The binding should looks as follows:

    <TextBlock.Foreground>
        <MultiBinding Converter="{StaticResource MultiConverter}" >
            <Binding Path="Data" Mode="OneWay"/>
            <Binding Path="DataContext.Orders" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type pivot:RadPivotGrid}}" />
        </MultiBinding>
    </TextBlock.Foreground>

    And an example for the converter Convert method:

    public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        var value = (double)((CellAggregateValue)values[0]).Value;
        var itemsSource = ((IEnumerable)values[1]).Cast<Order>().ToList();
     
        // you can implement custom logic here
        if (value < 1500)
        {
            return Brushes.Yellow;
        }
     
        return Brushes.Blue;
    }

    However please note that the information displayed in each cell doesn't represent a single item from the ItemsSource - it represents multiple items.

    Hope this will help you to achieve the desired.

    Regards,
    Kalin
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top
UI for WPF is Visual Studio 2017 Ready