binding error on styled base on TreeListViewRow with binding template

7 posts, 0 answers
  1. Julien
    Julien avatar
    20 posts
    Member since:
    Oct 2013

    Posted 23 Oct 2013 Link to this post

    Hello,

    I tried to customize style TreeListViewRow to add behavior, but i met a problem to keep the default alternating row style (row white and grey)
    Indeed, I Have the default alternating style in my RadTreeListView, but if I customize only the row style, I lost the alternating row style (all the row are white)
    So I decide to customize also the alternating row style, based on the row style.

    <Style
                    x:Key="rowStyle"
                    BasedOn="{StaticResource {x:Type telerik:TreeListViewRow}}"
                    TargetType="{x:Type telerik:TreeListViewRow}">
                    <Style.Setters>
                        <EventSetter
                            Event="MouseDoubleClick"
                            Handler="HandleRowDoubleClick" />
                    </Style.Setters>
                </Style>
     
                <Style
                    x:Key="alternateRowStyle"
                    BasedOn="{StaticResource rowStyle}"
                    TargetType="{x:Type telerik:TreeListViewRow}">
                </Style>

    But with this, I lost also the alternating row background color

    I set the background color of the style with bind of the AlternateRowBackground of the control (to keep inheritance).
    <Style
                    x:Key="alternateRowStyle"
                    BasedOn="{StaticResource rowStyle}"
                    TargetType="{x:Type telerik:TreeListViewRow}">
                    <Style.Setters>
                        <Setter
                            Property="Background"
                            Value="{Binding AlternateRowBackground, Source={RelativeSource TemplatedParent}}" />
                    </Style.Setters>
                </Style>


    With this, it's work, but I have binding error on each alternate line : BindingExpression path error: 'AlternateRowBackground' property not found on 'object' ''RelativeSource' (HashCode=46024298)'. BindingExpression:Path=AlternateRowBackground; DataItem='RelativeSource' (HashCode=46024298); target element is 'TreeListViewRow' (Name=''); target property is 'Background' (type 'Brush')

    I undestand If the color work, it's because when binding fail, telerik engine seems to put the default value, because Value={Binding Foo or whatever produce the same result.

    So I think it's because the AlternateRowBackground property isn't set in my RadTreeListView, I do this with yellow for test, but same error! (binding error, and the alternate background color is grey). I don't understand, can you explain this ?

    Thanks,

    Sincerly

    Gourdon Julien

    PS : sorry for my english, I'm french
  2. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 28 Oct 2013 Link to this post

    Hi,

     WIth this style you are trying to bind a property (Background) to the AlternateRowBackground property of the templated parent (TreeListViewRow). However, AlternateRowBackground is a property of RadTreeListView (inherited from GridViewDataControl) and not one of TreeListViewRow, so the biding source is not correct. You can try using RelativeSource AncestorOfType=telerik:RadTreeListView instead.

    Regards,
    Ivan Ivanov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Julien
    Julien avatar
    20 posts
    Member since:
    Oct 2013

    Posted 28 Oct 2013 Link to this post

    Thanks for your response,

    but I have exactly the same problem 

    <Style
                    x:Key="alternateRowStyle"
                    BasedOn="{StaticResource rowStyle}"
                    TargetType="{x:Type telerik:TreeListViewRow}">
                    <Style.Setters>
                        <Setter
                            Property="Background"
                            Value="{Binding AlternateRowBackground, Source={RelativeSource AncestorType={x:Type telerik:RadTreeListView}}}" />
                    </Style.Setters>
                </Style>

    other idea ?

    Sincerely,

    Gourdon Julien
  5. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 28 Oct 2013 Link to this post

    Hello,

     What is the binding error now? It should be different as the source has been updated. Could you please send us a runnable dummy sample project, which we would be able to debug on our side?

    Regards,
    Ivan Ivanov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  6. Julien
    Julien avatar
    20 posts
    Member since:
    Oct 2013

    Posted 29 Oct 2013 Link to this post

    this is the same error, shown in output view : 
    System.Windows.Data Error: 40 : BindingExpression path error: 'AlternateRowBackground' property not found on 'object' ''RelativeSource' (HashCode=50579267)'. BindingExpression:Path=AlternateRowBackground; DataItem='RelativeSource' (HashCode=50579267); target element is 'TreeListViewRow' (Name=''); target property is 'Background' (type 'Brush')
    contrary to what I said before, the row background not work (alternation work, but not the color). The alternate row should have the AliceBlue color, but it's white due to the binding error.
    You can find the sample project here

    Thanks,

    Gourdon Julien
  7. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 01 Nov 2013 Link to this post

    Hi,

     Can you please change the AlternateRowStyle like this:

    <Style
                x:Key="alternateRowStyle"
                BasedOn="{StaticResource rowStyle}"
                TargetType="{x:Type telerik:TreeListViewRow}">
                <Style.Setters>
                    <Setter
                        Property="Background"
                        Value="{Binding AlternateRowBackground, RelativeSource={RelativeSource AncestorType={x:Type telerik:RadTreeListView}}}" />
     
                </Style.Setters>
            </Style>
    Previous binding was syntactically broken, so that background was retrieved as null. This was resulting in row transperency, exposing the RadTreeListView background beneath.

    Regards,
    Ivan Ivanov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  8. Julien
    Julien avatar
    20 posts
    Member since:
    Oct 2013

    Posted 04 Nov 2013 Link to this post

    Thanks, it works ! 

    I doesn't know that Source={RelativeSource was different to RelativeSource={RelativeSource

    Problem solved
Back to Top
UI for WPF is Visual Studio 2017 Ready