I'm having problems in displaying a self referencing hierarchy using the radtreeview. The parent and child node appears on the same level. Please see the attached picture. I'm using the WCF RIA Services as the data provider. The context tree will load once the Id of a Paper is retrieved. I've tried following the self referencing guide in the blog but i can't seem to assign the DataContext to my EntityCollection. Is there any other way to do this? Here's my code.
DomainService
DtoClass
Code Behind
XAML
7 Answers, 1 is accepted
Please find attached a sample project illustrating how to populate RadTreeView with self-referencing data using RIA Services.
I hope it helps. Let us know if you need more info.
Best wishes,
Tina Stancheva
the Telerik team
Thanks for the quick response.
First - your solution is using load-on-demand. Is this compulsory?
Second - your solution is using LoadOperation Entities which is read-only and there is no built in INotifyPropertyChanged. Can you show me how to implement this using the EntityCollection?
Third - Can you elaborate more on the ItemPrepared event?
Regards,
Shaikh
I'll get straight to your questions:
1. No, you don't have to use LoadOnDemand feature at all costs. You can instead load all items and set only those with ParentId=null as an ItemsSource of the RadTreeView, like so:
void
TreeViewPage_Loaded(
object
sender, RoutedEventArgs e)
{
LoadOperation operation = context.Load(context.GetMyDataTablesQuery());
operation.Completed +=
new
EventHandler(operation_Completed);
}
void
operation_Completed(
object
sender, EventArgs e)
{
this
.myTreeView.ItemsSource = context.MyDataTables.Where(i => i.ParentID ==
null
);
}
[MetadataTypeAttribute(
typeof
(MyDataTable.MyDataTableMetadata))]
public
partial
class
MyDataTable
{
// This class allows you to attach custom attributes to properties
// of the MyDataTable class.
...
internal
sealed
class
MyDataTableMetadata
{
// Metadata classes are not meant to be instantiated.
private
MyDataTableMetadata()
{
}
[Include(
"Count"
,
"ChildrenCount"
)]
[Include]
public
IList<MyDataTable> Children {
get
;
set
; }
public
int
ID {
get
;
set
; }
public
int
ParentID {
get
;
set
; }
public
string
Text {
get
;
set
; }
}
}
2. Instead of the LoadOperation Entities collection, you can use the context.MyDataTables as shown above. Also, another approach is to use the Entities collection, but wrap it in an ObservableCollection, for example:
void
TreeViewPage_Loaded(
object
sender, RoutedEventArgs e)
{
LoadOperation operation = context.Load(context.GetMyDataTablesQuery());
operation.Completed +=
new
EventHandler(operation_Completed);
}
void
operation_Completed(
object
sender, EventArgs e)
{
ObservableCollection<Entity> wrapCollection =
new
ObservableCollection<Entity>((sender
as
LoadOperation).Entities);
this
.myTreeView.ItemsSource = wrapCollection;
}
3. More information about the ItemPrepared() event you can find here.
I also modified the example to illustrate an approach without the RadTreeView LoadOnDemand feature. Take a look at it and the info and let me know if I can further assist you.
All the best,
Tina Stancheva
the Telerik team
I found this thread very usefull to me... I have a question here ..
How can I bind the LoadOnDemand to Command as so : LoadOnDemand="{Binding ItemExpandedCommand}" where is command is define in my VM.
Best regards
Waleed
Please let us know if the answer here satisfies you or not. Feel free to ask if you need further assistance. You could provide a sample if things are getting too complex to explain. This way we could advice you better.
Regards,
Petar Mladenov
the Telerik team
Thank you for your interest in OpenAccess ORM.
While there isn't such sample with OpenAccess, you can convert your edmx model to OpenAccess Domain Model using the Convert from Entity Framework wizard.
OpenAccess ORM also offers a RIA wizard, generating the service for your convenience. You can use it or just create the service definition manually (in case of the specified sample - just use the same infrastructure). The wizard supports Silverlight 3 and 4, but doesn't support Silverlight 5 yet.
In general you can download the OpenAccess SDK if you need sample projects - we do have a Silverlight example there.
Let us know if you have any questions or you need assistance in using OpenAccess ORM in Silverlight applications. You are welcome to start a separate thread in the OpenAccess forums for that purpose.
Ivailo
the Telerik team