Bind RadTreeView to XML

13 posts, 0 answers
  1. V
    V avatar
    9 posts
    Member since:
    Jun 2010

    Posted 02 Nov 2010 Link to this post

    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

     

  2. Zarko
    Admin
    Zarko avatar
    755 posts

    Posted 05 Nov 2010 Link to this post

    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
  3. DevCraft banner
  4. Luciano
    Luciano avatar
    11 posts
    Member since:
    Jun 2012

    Posted 12 May 2011 Link to this post

    Hi,
    Starting from this example how can I add a node to treview?
  5. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 13 May 2011 Link to this post

    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
  6. Luciano
    Luciano avatar
    11 posts
    Member since:
    Jun 2012

    Posted 18 May 2011 Link to this post

    Thanks, I'll need to edit the node name and if possible a button that allows me to calculate the 'xml format string.
    Luciano
  7. Bala
    Bala avatar
    20 posts
    Member since:
    Dec 2011

    Posted 04 Mar 2012 Link to this post

    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



  8. Bala
    Bala avatar
    20 posts
    Member since:
    Dec 2011

    Posted 05 Mar 2012 Link to this post

    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

     
  9. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 06 Mar 2012 Link to this post

    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 >>
  10. Bala
    Bala avatar
    20 posts
    Member since:
    Dec 2011

    Posted 06 Mar 2012 Link to this post

    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.

  11. Bala
    Bala avatar
    20 posts
    Member since:
    Dec 2011

    Posted 06 Mar 2012 Link to this post

    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

  12. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 09 Mar 2012 Link to this post

    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 >>
  13. Bala
    Bala avatar
    20 posts
    Member since:
    Dec 2011

    Posted 16 Mar 2012 Link to this post

    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
  14. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 20 Mar 2012 Link to this post

    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 >>
Back to Top
DevCraft banner