Set behavior for all GridViews

3 posts, 0 answers
  1. Marnic
    Marnic avatar
    4 posts
    Member since:
    Dec 2017

    Posted 02 Jan Link to this post

    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. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    655 posts

    Posted 04 Jan Link to this post

    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.
  3. Marnic
    Marnic avatar
    4 posts
    Member since:
    Dec 2017

    Posted 04 Jan in reply to Dilyan Traykov Link to this post

    Hello Dilyan,

    works like a charm ! Thanks a lot !

    Kind Regards

Back to Top