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

How to Binding in telerik:GridViewColumn.Footer

6 Answers 484 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jihong
Top achievements
Rank 1
Jihong asked on 05 Jan 2011, 03:01 AM

Dear Support,

I want to Binding to GridView.SelectedItems.Count or other DependencyProperty, but it returns nothing, no error no exception. Please help me how to Binding in telerik:GridViewColumn.Footer.

Other test results:

  • Binding to AggregateFunctions works fine.
  • Binding to GridView.SelectedItems.Count or other DependencyProperty out of the range of GridView works fine.

Code is below:

<telerik:GridViewDataColumn Header="PO Number" DataMemberBinding="{Binding PONUMBER}">
    <telerik:GridViewDataColumn.AggregateFunctions>
        <custom:CountDistinctFunction Caption="Distinct PO Count:" />
    </telerik:GridViewDataColumn.AggregateFunctions>
    <telerik:GridViewDataColumn.Footer>
        <StackPanel Orientation="Vertical" Margin="0">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="Selected:" />
                <TextBlock Text="{Binding ElementName=myGridView, Path=SelectedItems.Count}" />
            </StackPanel>
            <telerik:AggregateResultsList ItemsSource="{Binding}" VerticalAlignment="Center">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                            <TextBlock VerticalAlignment="Center" Text="{Binding Caption}" />
                            <TextBlock VerticalAlignment="Center" Text="{Binding FormattedValue}" />
                        </StackPanel>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </telerik:AggregateResultsList>
        </StackPanel>
    </telerik:GridViewDataColumn.Footer>
</telerik:GridViewDataColumn>

Thanks for your support.

6 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 05 Jan 2011, 09:01 AM
Hello Jihong,

A possible way for achieving the desired result is to use the FooterCellStyle and define its ContentTemplate as follows:

<Grid.Resources>
 <Style x:Key="GridViewFooterTotalCellStyle" TargetType="telerik:GridViewFooterCell">
         <Setter Property="ContentTemplate">
                <Setter.Value>
                     <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="Selected: " />
                            <TextBlock Text="{Binding Path=SelectedItems.Count,                              
                                       RelativeSource={RelativeSource AncestorType=telerik:RadGridView}}"    
                                      />
                            </StackPanel>
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Grid.Resources>
  
Afterwards you need to set the FooterCellStyle property of the column:
<telerik:GridViewDataColumn DataMemberBinding="{Binding Number}"
       FooterCellStyle="{StaticResource GridViewFooterTotalCellStyle}">


Kind regards,
Maya
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
Jihong
Top achievements
Rank 1
answered on 05 Jan 2011, 11:00 AM
Got below exception after adding and implementing the Style:

Type reference cannot find public type named 'RadGridView'.

my code:
<Style x:Key="GridViewFooterSelectedCountCellStyle" TargetType="telerik:GridViewFooterCell">
            <Setter Property="ContentTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="??: " />
                            <TextBlock Text="{Binding Path=SelectedItems.Count,                               
                                       RelativeSource={RelativeSource AncestorType=telerik:RadGridView}}" />
                        </StackPanel>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>

And ff I modify AncestorType to UserControl, and programm can Binding a DependentProperty successfully.

Thanks.
0
Jihong
Top achievements
Rank 1
answered on 05 Jan 2011, 11:05 AM
Probably because I put the code in a wrong place, I am testing it.
0
Jihong
Top achievements
Rank 1
answered on 05 Jan 2011, 11:09 AM
I put the Style code in UserControl.Resources scope, is it right?
0
Maya
Telerik team
answered on 05 Jan 2011, 11:14 AM
Hello Jihong,

I am sending you a sample project illustrating the proposed solution. Please take a look at it for a reference and let me know in case you need any further assistance.
 

Greetings,
Maya
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
Wayne
Top achievements
Rank 1
answered on 17 Jul 2011, 02:16 PM

Hi,

I have the same problem but not using WPF, I’m using Silverlight. The demo works well. Do you have one for Silverlight? I cannot get the Window.Resoures.

Thank you

Wayne

Tags
GridView
Asked by
Jihong
Top achievements
Rank 1
Answers by
Maya
Telerik team
Jihong
Top achievements
Rank 1
Wayne
Top achievements
Rank 1
Share this question
or