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

Setting ScrollPositionIndicatorTemplate Binding in CodeBehind

1 Answer 130 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Adam asked on 18 Apr 2011, 11:34 PM
So I am trying to dynamically build a datagrid, and I want to be able to have eh scroll position indicator bind to a different column at different times.

How do I change which column the ScrollPositionIndicatorTemplate's ContentPresenter binds to in the code behind?

I tried the following (and numerous variants thereof!) to no avail:

Binding binding = new Binding("Data.FirstName");  
            ScrollPositionIndicator indicator = this.RadGridView1.ChildrenOfType<ScrollPositionIndicator>().First();  
            ContentPresenter presenter = indicator.ChildrenOfType<ContentPresenter>().First();  
            presenter.SetBinding(ContentPresenter.ContentProperty, binding);

1 Answer, 1 is accepted

Sort by
Vanya Pavlova
Telerik team
answered on 19 Apr 2011, 01:20 PM
Hello Adam,


In my opinion the better approach here is to define a single DataTemplate in a UserControl's Resource Collection and in code behind just change the ScrollPositionIndicatorTemplate of RadGridView as shown below:


    <DataTemplate x:Key="dt">
        <TextBlock Text="{Binding EmployeeName}"/>
    <Grid x:Name="LayoutRoot" Background="White" DataContext="{Binding Source={StaticResource SampleDataSource}}">
        <telerik:RadGridView x:Name="radGridView" ScrollMode="Deferred" ItemsSource="{Binding Collection}" AutoGenerateColumns="False">
                <telerik:GridViewDataColumn Header="ID" DataMemberBinding="{Binding ID}"/>
                    <telerik:GridViewDataColumn Header="EmployeeName" DataMemberBinding="{Binding EmployeeName}"/>
                        <telerik:GridViewDataColumn Header="CompanyName" DataMemberBinding="{Binding CompanyName}"/>
                            <telerik:GridViewDataColumn Header="?" DataMemberBinding="{Binding IsMarried}"/>
        <Button Content="Button" HorizontalAlignment="Left" Height="24" Margin="240,0,0,8" VerticalAlignment="Bottom" Width="72" Click="Button_Click"/>


private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
    // TODO: Add event handler implementation here.
    this.radGridView.ScrollPositionIndicatorTemplate = this.Resources["dt"] as DataTemplate;

Vanya Pavlova
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Asked by
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Share this question