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

Doesn't Refresh

3 Answers 86 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 25 Apr 2012, 08:46 PM
Hello i was developed a TreeView. When i insert a node from constructor do it perfectly, but if i call the "addNode" from other function, nothing appear.

My xaml code is:
<Grid x:Name="LayoutRoot" Background="White">
        <telerik:RadTreeView x:Name="uxtTreeView_Model" />
    </Grid>

All is code behind.

If i call the addNode from the constructor or add de node directly works but call from other class doesn't work

By example this:
  public void addRootNode()
        {
            RadTreeViewItem itemRaiz = new RadTreeViewItem();
            itemRaiz.Name = "<root>";
            itemRaiz.Header = "<No Elements>";
            uxtTreeView_Model.Items.Add(itemRaiz);
        }

Call from constructor works, but if i do a instation of the this class and call the function, does not work

3 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 27 Apr 2012, 12:36 PM
Hello,

The issue you are describing sounds really strange. I wasn't able to simulate it, thus attached a sample project showing my attempt.

Could you please modify my project in order to introduce the issue?

Greetings,
Hristo
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
David
Top achievements
Rank 1
answered on 29 Apr 2012, 04:46 PM
Hello. Thanks for the answer. 

In your example all code are in the main file, the problem is if you want have code in another usercontrol in a different xaml file, using a xmlns:local, by example.

Code of main.xaml:

<UserControl x:Class="EjTreeTelerik.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:EjTreeTelerik"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">


    <Grid x:Name="LayoutRoot" Background="White">
        <local:customArbol x:Name="cArbol"></local:customArbol>


    </Grid>
</UserControl>

code of main.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;


namespace EjTreeTelerik
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            cargaElementosArbol();
        }


        private void cargaElementosArbol()
        {
            customArbol c = new customArbol();
            c.carga();
            LayoutRoot.DataContext = c;          
          
        }
    }
}



Now we have the telerik component:

customArbol.xaml (arbol in Tree in spanish )


<UserControl x:Class="EjTreeTelerik.customArbol"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
              xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
    d:DesignHeight="300" d:DesignWidth="400">
    
    <Grid x:Name="LayoutRoot" Background="White">
        <telerik:RadPaneGroup>
            <!--Arbol del proyecto-->
            <telerik:RadPane Header="Model Explorer">
                <!-- 
                        <customControls:ctlTreeModel></customControls:ctlTreeModel>
                    -->
                <telerik:RadTreeView x:Name="uxtTreeView_Model" />


            </telerik:RadPane>
        </telerik:RadPaneGroup>
    </Grid>
</UserControl>

Code of customArbol.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;


namespace EjTreeTelerik
{
    public partial class customArbol : UserControl
    {
        public customArbol()
        {
            InitializeComponent();           
        }


        public void carga()
        {
            RadTreeViewItem itemRaiz = new RadTreeViewItem();
            itemRaiz.Name = "<root>";
            itemRaiz.Header = "Acabamos de invocar la funcion";
            uxtTreeView_Model.Items.Add(itemRaiz);
        }
    }
}








0
Tina Stancheva
Telerik team
answered on 02 May 2012, 02:52 PM
Hello David,

Thank you for sending your sample code. However, there is one part of it that I can't understand. I noticed that once you create the new customArbol control, you're setting it as a DataContext of the LayoutRoot control. Can you please shed some light on why you've set the RadTreeView as a DataContext of the LayoutRoot element?

Also I created a sample solution based on your code snippets and I only changed the DataContext logic by placing the new customArbol control in the Children collection of the LayoutRoot:
private void cargaElementosArbol()
{
    customArbol c = new customArbol();
    c.carga();
    //LayoutRoot.DataContext = c;
    LayoutRoot.Children.Add(c);
}
 and it worked as expected. However, please let me know if I'm missing something.

Regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
TreeView
Asked by
David
Top achievements
Rank 1
Answers by
Hristo
Telerik team
David
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or