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

Binding to the IsExpandable Proeprty

4 Answers 102 Views
GridView
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 13 May 2010, 10:27 AM
Hi ... I have a child grid for which I would like to show the IsExpandable button only if there is data in the objects child collection. I have tried the following XAML
        <Style TargetType="{x:Type Controls:GridView.GridViewRow}">
            <Setter Property="IsExpandable" Value="{Binding DeviceBehaviours.Count, Converter={StaticResource IntegerToBooleanConverter}, Mode=OneWay}" />
        </Style>
The converter returns a boolean if the child collection has a count. This collection is asynchronous and returns a only result after the RowLoaded event has already run. 

Weirdly this same Xaml works for the Expanded property.

Hope you can help
John .


4 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 14 May 2010, 12:55 PM
Hi John Darlington,

You may take a look at our online demo that shows exactly what you need - hiding the toggle button for those rows that do not have child hierarchy. The relevant code is in the RowLoaded event handler. 

I hope that helps.

All the best,
Maya
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.
0
John
Top achievements
Rank 1
answered on 15 May 2010, 07:20 AM
Thanks for looking at this for me ...  The problem with our situation is that the child collection is loaded asyncronously so that when the parent grid loads for the first time, the child collection count is zero. The Data Access Layer then populates the child collection after the RowLoaded event has already run.  I am hoping to avoid the situation where I will need to spawn a background thread some time after the grid has loaded to recheck the Child Collection counts.

Hope you can help

John
0
Maya
Telerik team
answered on 17 May 2010, 07:53 AM
Hi John Darlington,

In your case when data is loaded asynchronous, the method you have chosen with Converter and setting the binding to the count of the child is quite appropriate. However, we apply some custom logic into the property IsExpandable and that is why it does not work when it is defined in xaml. 
What you need to do is to set the binding in the code-behind.
I am sending you a sample project so that you can test the proposed solution. 
In this project two possible approaches are implemented and you are free to use whichever you prefer. 
The first one is to attach behaviors and to defined them in xaml. The class that implements Behavior<RadGridView> is IsExpandableBehavior and the property that "commands" that behavior is IsExpandableSourcePropertyName - in this case it corresponds to the count of the elements in the child table. Its definition in xaml is:

<i:Interaction.Behaviors>
    <my:IsExpandableBehavior IsExpandableSourcePropertyName="Players.Count/> </i:Interaction.Behaviors>

The other possible approach will be to set the binding during the RowLoaded event and to clear it during RowUnloaded event. 
In this project the first approach is used, but still the code for the RowLoaded and RowUnloaded events is left so that you can see it. 
The methods LoadPlayersAsync() and GetClubPlayers(Club club) are created only for testing the functionality with asynchronous loading of data - as it is you case. 

 

Sincerely yours,
Maya
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.
0
John
Top achievements
Rank 1
answered on 20 May 2010, 09:18 AM
Brilliant ... thanks for taking the time to provide such a detailed response ...
Tags
GridView
Asked by
John
Top achievements
Rank 1
Answers by
Maya
Telerik team
John
Top achievements
Rank 1
Share this question
or