Simple databound treeview doesnt work, why?

3 posts, 1 answers
  1. Frank -
    Frank - avatar
    8 posts
    Member since:
    Apr 2010

    Posted 10 Jun 2011 Link to this post

    I have a treeview in its simples form possible, can anyone explain why this little piece of code doesnt show my tree?

    <UserControl x:Class="treeview.MainPage"
        xmlns:telerikNav="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"
        xmlns:telerikCon="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"             
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="400">
      
        <Grid x:Name="LayoutRoot" Background="White">
            <telerikNav:RadTreeView Background="HotPink" ItemsSource="{Binding ParentList}"/>    
        </Grid>
    </UserControl>


    Imports System.ComponentModel
    Imports System.Collections
    Imports System.Collections.ObjectModel
      
    Partial Public Class MainPage
        Inherits UserControl
      
        Public ParentList As New ObservableCollection(Of String)
      
        Public Sub New()
            InitializeComponent()
            PopulateList()
        End Sub
      
        Public Sub PopulateList()
            ParentList.Add("test")
            ParentList.Add("test1")
        End Sub
    End Class

    The background - hotpink displays but not test and test1 strings as expected.. Any ideas?
  2. Answer
    Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 15 Jun 2011 Link to this post

    Hello Frank -,

    You haven't specified DataContext for the RadTreeView. I can suggest you to set the ItemsSource directly from code behind like so:
    <telerikNav:RadTreeView Background="HotPink" x:name="tree">
    Public Sub PopulateList() 
            ParentList.Add("test"
            ParentList.Add("test1"
            this.tree.ItemsSource = ParentList;
        End Sub
    Let us know if you need further assistance on this.


    Best wishes,
    Petar Mladenov
    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. Frank -
    Frank - avatar
    8 posts
    Member since:
    Apr 2010

    Posted 15 Jun 2011 Link to this post

Back to Top