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

Bind RadTreeView to XML

12 Answers 217 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
V
Top achievements
Rank 1
V asked on 02 Nov 2010, 08:36 PM
I've read the tutorials on binding the Silverlight RadTreeView to XML, however I still can't figure this out! It's so simple with the .NET TreeView, yet so complicated with the Silverlight controls.

I'm returning from a class an XML string (returned from a stored procedure into a CSLA object):

 

<Tree>
  
    <Node Value="4641" Text="Test Parent Node 1" Expanded="true" />
        <Node Value="1234" Text="Test Child Node 1" Expanded = "true" />
     </Node>
</Tree>

 

in .Net, you could simply do a TreeView.LoadXml(xmlString).

How do you do the equivalent in Silverlight?

Can anyone help? The example say to deserialize from a reader, etc. But I can't get it to work...can anyone point me in the right direction???

Thanks!

V

 

12 Answers, 1 is accepted

Sort by
0
Zarko
Telerik team
answered on 05 Nov 2010, 03:11 PM
Hi V,

 I think this article is what you are looking for. I've also sent you a sample project, so could you please examine it and if you have further questions feel free to ask?

Kind regards,
Zarko
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
Luciano
Top achievements
Rank 1
answered on 12 May 2011, 10:42 AM
Hi,
Starting from this example how can I add a node to treview?
0
Kiril Stanoev
Telerik team
answered on 13 May 2011, 01:02 PM
Hi Luciano,

I've updated the previous project to demonstrate adding a new items to the TreeView as well as saving the newly created structure to the IsolatedStorage.
Please take a look at the attached project and let me know how it works for you.

Greetings,
Kiril Stanoev
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
Luciano
Top achievements
Rank 1
answered on 18 May 2011, 07:32 AM
Thanks, I'll need to edit the node name and if possible a button that allows me to calculate the 'xml format string.
Luciano
0
Bala
Top achievements
Rank 1
answered on 05 Mar 2012, 05:57 AM
Hi,


 i need to expand the Particular Node Programatically. I will be sending a particular Node Header text  Programatically . i need to expand that Node's.

as per example
 - >ANIMAL - Dog

like Fish|Fresh Water|roach

similiar to this example --

 

rad.SelectItemByPath(

 

"Fish|Fresh Water|roach");

 

rad.PathSeparator =

 

"|";

 

rad.ExpandItemByPath(iop);

So that i can expand the node's programatically.


can u plz make it asap....


Looking for ur reply,
bala s



0
Bala
Top achievements
Rank 1
answered on 05 Mar 2012, 06:04 AM
Hi Kiril,


 can u plz help me with this .....
   i m already working with treeview as source as sql db. Since i m finding a delay in binding process. i m planning to move to XML binding.

But i m unnable to programatically expand its Node.which i m able to do in normal radtree view. Similirlly like this 
Ex:

rad.SelectItemByPath(

 

"Fish|Fresh Water");

 

rad.PathSeparator =

 

"|";

 

rad.ExpandItemByPath(iop);


but i m uable to expand the Node. could u Plz guide me with this. 

Looking for ur response at the earliest,
Bala s

 
0
Hristo
Telerik team
answered on 06 Mar 2012, 11:00 AM
Hi,

Could you take a look at the following code segments and give them a try (I'm using the treeviewxmlbinding.zip attached project).

<telerik:RadTreeView x:Name="thetree" ItemTemplate="{StaticResource Item}" Loaded="RadTreeView_Loaded"
        ItemsSource="{Binding Source={StaticResource treeViewData}}"
        telerik:TextSearch.TextPath="Header"/>

private void RadTreeView_Loaded(object sender, RoutedEventArgs e)
{
    this.thetree.BringPathIntoView(@"Fish\Fresh Water\Roach");
}


There are two important steps:
1) Set the TextPath attached property in xaml (use the  telerik schema).
2) Call the BringPathIntoView method with the correct path.

Hope this helps.
Regards,
Hristo
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Bala
Top achievements
Rank 1
answered on 07 Mar 2012, 05:11 AM
Hi Hristo ,


  i m following only the same  treeviewxmlbinding.zip  sample. And i included 

<

 

 

Grid.Resources>

 

 

 

 

<local:RadTreeViewXmlDataSource x:Key="treeViewData" Source="SampleXML.xml" />

 

 

 

 

<telerik:HierarchicalDataTemplate x:Key="Item" ItemsSource="{Binding Items}" telerik:TextSearch.TextPath="Header">

 

 

 

 

<TextBlock Text="{Binding Header}" />

 

 

 

 

</telerik:HierarchicalDataTemplate>

 

 

 

 

</Grid.Resources>

 

 

 

 

<telerik:RadTreeView Name="rad" ItemTemplate="{StaticResource Item}"

 

 

 

ItemsSource="{Binding Source={StaticResource treeViewData}}" Selected="rad_Selected" telerik:TextSearch.TextPath="Header"/>

 

 

 

 

</Grid>

but i'm unable to Expand nodesusing -

 

this.rad.BringPathIntoView(@"Fish\Fresh Water\Roach");


could u plz reply ... me.

0
Bala
Top achievements
Rank 1
answered on 07 Mar 2012, 05:31 AM
Hi Hristo,

 extremly Sorry for the Reply to the post. i'm able get it .I m able to expand Nodes Now. I got the Issue cleared. and If U don't mind.

could u plz describe me regarding the  Search Method To search for a node in Treeview for a particular node using Search option from a Textcolumn?


thks for ur kind help

0
Petar Mladenov
Telerik team
answered on 09 Mar 2012, 05:26 PM
Hello Bala ,

 Could you please elaborate more on your sceanario, what do you exactly mean with "Method To search for a node in Treeview for a particular node using Search option from a Textcolumn "? Could you please check out the following article and  let us know if it satisfies you? Basically it shows how to iterate over the RadTreeViewItems. In databinding scenarios, you may  need to traverse the ViewModel hierarchy and the get the corresponding RadTreeViewItem by invoking the GetItemByPath() method.

All the best,
Petar Mladenov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Bala
Top achievements
Rank 1
answered on 16 Mar 2012, 06:36 AM
hi ,


 thanks for ur previous posts. i need now to highlight the text that i search for . So that i can show the text highlighted that i search for . and i need it for both binding methods.(treeview binding using  database  & treeview binding using XML Methods).



looking for ur Highlighted Post,
Bala s
0
Petar Mladenov
Telerik team
answered on 20 Mar 2012, 12:53 PM
Hello Bala,

 Let's suppose you have found a ViewModel after you have traversed the ViewModel hierarchy. Then you can get the RadTreeViewItem (the visual container for the ViewModel/objecy) with the method RadTreeView.ContainerFromItemRecursive(object item). Once you have the RadTreeViewitem, its Header property will return the Panel/Control used in the DataTempalte that is set as an ItemTemplate of the RadTreeView.
 In other words if you have:

<DataTemplate x:key="itemtemplate">
   <TextBlock Text="{Binding Name}" />
</DataTemplate>
the Header will give you the TextBlock. Unfortunately, in SIlverlight , the TextBlock does not have Background property that you can use for highlighting. So you can have DataTemplate like so:
<DataTemplate x:key="itemtemplate">
   <Grid>
      <TextBlock Text="{Binding Name}" />
   </Grid>
</DataTemplate>
This way the Header will give you the Grid and you will be able to use its Background.
Hope this helps you.


Kind regards,
Petar Mladenov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
TreeView
Asked by
V
Top achievements
Rank 1
Answers by
Zarko
Telerik team
Luciano
Top achievements
Rank 1
Kiril Stanoev
Telerik team
Bala
Top achievements
Rank 1
Hristo
Telerik team
Petar Mladenov
Telerik team
Share this question
or