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

binding error on styled base on TreeListViewRow with binding template

6 Answers 113 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Julien
Top achievements
Rank 1
Julien asked on 23 Oct 2013, 01:47 PM
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

6 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 28 Oct 2013, 02:43 PM
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 >>
0
Julien
Top achievements
Rank 1
answered on 28 Oct 2013, 02:51 PM
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
0
Ivan Ivanov
Telerik team
answered on 28 Oct 2013, 02:57 PM
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 >>
0
Julien
Top achievements
Rank 1
answered on 29 Oct 2013, 07:24 AM
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
0
Ivan Ivanov
Telerik team
answered on 01 Nov 2013, 01:21 PM
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 >>
0
Julien
Top achievements
Rank 1
answered on 04 Nov 2013, 07:10 AM
Thanks, it works ! 

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

Problem solved
Tags
TreeListView
Asked by
Julien
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Julien
Top achievements
Rank 1
Share this question
or