Doesn't Refresh

4 posts, 0 answers
  1. David
    David avatar
    11 posts
    Member since:
    Apr 2012

    Posted 25 Apr 2012 Link to this post

    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
  2. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 27 Apr 2012 Link to this post

    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 >>

  3. DevCraft banner
  4. David
    David avatar
    11 posts
    Member since:
    Apr 2012

    Posted 29 Apr 2012 Link to this post

    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);
            }
        }
    }








  5. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 02 May 2012 Link to this post

    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 >>

Back to Top