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

Set behavior for all GridViews

2 Answers 668 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marnic
Top achievements
Rank 1
Marnic asked on 02 Jan 2018, 09:10 AM

Hi,

I created a behavior to scroll to the selected item in a RadGridView when the selected item is set programmatically. Basically, I used Dan's answer in this post: https://www.telerik.com/forums/scroll-to-row-when-programmatically-setting-selected-item.

This works fine when applying the behavior directly to the grid as in following example

 <telerik:RadGridView Grid.Column="2"  ItemsSource="{Binding StockSvtCollectionView}" SelectedItem="{Binding CurrentModel}" GroupRenderMode="Flat"          AutoGenerateColumns="False" IsReadOnly="True" ShowGroupFooters="True" ShowColumnFooters="True" AutoExpandGroups="True" Margin="0,-10,0,10">

            <i:Interaction.Behaviors>
                <uct:RadGridViewScrollSelectedItemIntoViewBehavior/>
            </i:Interaction.Behaviors>


Now I'm looking for an easy way to apply this behvior to all my GridViews.  I tried using a style:

    <Style x:Key="DefaultTelerikGridView" TargetType="{x:Type telerik:RadGridView}">

        <Style.Setters>
            <Setter Property="i:Interaction.Behaviors">
            <Setter.Value>
                <uct:RadGridViewScrollSelectedItemIntoViewBehavior/>
            </Setter.Value>
            </Setter>
            <Setter Property="telerik:StyleManager.Theme" Value="{StaticResource DefaultTelerikApplicationTheme}"/>
        </Style.Setters>
    </Style>
    <Style TargetType="{x:Type telerik:RadGridView}" BasedOn="{StaticResource DefaultTelerikGridView}"/>

But this generates this error:

The property "Behaviors" is not a DependencyProperty. To be used in markup, non-attached properties must be exposed on the target type with an accessible instance property "Behaviors". For attached properties, the declaring type must provide static "GetBehaviors"  and "SetBehaviors"

Any help would be much appreciated.

2 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 04 Jan 2018, 10:55 AM
Hello Marnic,

To achieve the desired result, you can introduce an attached property as demonstrated in this article.

For your convenience, I'm attaching a sample project with the implementation. Please let me know if you find it helpful.

Regards,
Dilyan Traykov
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.
0
Marnic
Top achievements
Rank 1
answered on 04 Jan 2018, 01:36 PM

Hello Dilyan,

works like a charm ! Thanks a lot !

Kind Regards

Tags
GridView
Asked by
Marnic
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Marnic
Top achievements
Rank 1
Share this question
or