IsLoadOnDemandEnabled ignored

4 posts, 0 answers
  1. Josh
    Josh avatar
    27 posts
    Member since:
    Feb 2012

    Posted 24 Oct 2013 Link to this post

    In some of our screens, we use the LoadOnDemand feature of TreeViews by adding new RadTreeViewItems to recently expanded node.  Here's a sample event handler for how we do this:
    private void EventTreeView_LoadOnDemand(object sender, Telerik.Windows.RadRoutedEventArgs e)
    {
    var item = e.OriginalSource as RadTreeViewItem;
    var entity = item.DataContext as TestItem;
    item.IsLoadingOnDemand = true;
    var newItem = new TestItem {Name = entity.Name + " - 1"};
    item.Items.Add(new RadTreeViewItem
    {
    DataContext = newItem,
    Header = newItem.Name,
    IsLoadOnDemandEnabled = false
    });
    item.IsLoadingOnDemand = false;
    item.IsLoadOnDemandEnabled = false;
    }

    Previously, this would result in the new child item being the final leaf in the tree with no expand icon.  But after upgrading to the new Q3 controls, the TreeView is ignoring the value of the IsLoadOnDemandEnabled property of the new item and is allowing that item to be expanded.
  2. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 29 Oct 2013 Link to this post

    Hello,

    I tried to reproduce the reported behavior on our side with our latest official release and it seems that the code works as expected. Could you please take a look at the attached project and let me know if I missed something.

    It will be great if you can change the implementation so that the issue can be reproduced and sent the project over. By doing so we will be able to further investigate the possible reasons behind this issue.

    Thank you for your cooperation.

    Regards,
    Pavel R. Pavlov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. DevCraft banner
  4. Josh
    Josh avatar
    27 posts
    Member since:
    Feb 2012

    Posted 29 Oct 2013 Link to this post

    Hi Pavel,

    Thanks for your response.

    I didn't see anywhere in your sample project where you were setting IsLoadOnDemandEnabled = False for the child elements.  Below is the code for a simple project to reproduce the behavior I'm seeing.  Running the project with Q1 .dll's behaves as expected.  Running the project with Q3 .dll's results in the child elements always having LoadOnDemand enabled.

    MainPage.xaml
    <UserControl x:Class="TestTree.MainPage"
                 xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="400">
     
        <Grid x:Name="LayoutRoot" Background="White">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="300" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="2*" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
     
            <Grid Grid.RowSpan="3">
                <Grid.RowDefinitions>
                    <RowDefinition Height="2*" />
                    <RowDefinition Height="3*" />
                </Grid.RowDefinitions>
     
                <telerik:RadTabControl Grid.Row="0">
                    <telerik:RadTabItem Header="Test Tree">
     
                        <Grid>
                                 
                            <telerik:RadTreeView
                                x:Name="EventTreeView"
                                IsOptionElementsEnabled="True"
                                IsRootLinesEnabled="True"
                                IsLineEnabled="True"
                                IsTriStateMode="True"
                                DisplayMemberPath="Name"
                                ItemsSource="{Binding Entities}"
                                IsLoadOnDemandEnabled="True"
                                LoadOnDemand="EventTreeView_LoadOnDemand"/>
     
                        </Grid>
                    </telerik:RadTabItem>
                </telerik:RadTabControl>
            </Grid>
        </Grid>
    </UserControl>


    MainPage.xaml.cs
    using System.Collections.ObjectModel;
    using System.Windows.Controls;
    using Telerik.Windows.Controls;
     
    namespace TestTree
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
     
                var sd = new SampleData();
                DataContext = sd;
            }
     
            private void EventTreeView_LoadOnDemand(object sender, Telerik.Windows.RadRoutedEventArgs e)
            {
                var item = e.OriginalSource as RadTreeViewItem;
                var entity = item.DataContext as TestItem;
     
                item.IsLoadingOnDemand = true;
     
                var newItem = new TestItem {Name = entity.Name + " - 1"};
     
                item.Items.Add(new RadTreeViewItem
                                    {
                                        DataContext = newItem,
                                        Header = newItem.Name,
                                        IsLoadOnDemandEnabled = false
                                    });
     
                item.IsLoadingOnDemand = false;
                item.IsLoadOnDemandEnabled = false;
            }
            
        }
     
        public class SampleData : ViewModelBase
        {
            public SampleData()
            {
                LoadData();
            }
     
            private void LoadData()
            {
                IsBusy = true;
                OnPropertyChanged("IsBusy");
     
                for (int i = 0; i < 100; i++)
                {
                    Entities.Add(new TestItem { Name = i.ToString() });
                }
     
                IsBusy = false;
     
                OnPropertyChanged("Entities");
                OnPropertyChanged("IsBusy");
            }
     
            public bool IsBusy { get; set; }
     
            private ObservableCollection<TestItem> _entities;
            public ObservableCollection<TestItem> Entities
            {
                get { return _entities ?? (_entities = new ObservableCollection<TestItem>()); }
            }
        }
    }


    TestItem.cs
    namespace TestTree
    {
        public class TestItem
        {
            public string Name { get; set; }
        }
    }



  5. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 01 Nov 2013 Link to this post

    Hello Josh,

    Thank you for elaborating on your custom scenario. I can see that you have defined ItemsSoucre and at the same time you add UI elements to the control. Please note that this is considered as bad practice and we do not recommend using that approach.

    We suggest combining the load on demand feature with an MVVM architecture of your application. Such approach is demonstrated in the previously attached project. Note that the IsLoadOnDemandEnabled and the IsLoadingOnDemand properties of the RadTreeViewItem control are bound in TwoWay mode to properties exposed by the business class. By doing so you will be allowed to control them through your ViewModel. Furthermore, whenever you add a business item into the ItemsSource collection, the control will generate the corresponding container.

    I hope this clarifies your concerns.

    Regards,
    Pavel R. Pavlov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top