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

How to use both autoexpend on drag AND loadondemand?

1 Answer 149 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Jean-Christophe DESIRE
Top achievements
Rank 1
Jean-Christophe DESIRE asked on 18 Jul 2010, 11:45 PM
Hello,
I'm having issues getting the treeview's functionalities to work when in LoadOnDemand , notably drag and drop and AutoExpand,
1) AutoExpand on drag doesn't work , if i remove the load on demand it works , however load on demand itself seems to work just fine
2) Droping doesn't seem to load the node either , when i drop on an unloaded node it opens with only the node i have droped instead of it's actual content.
Is this scenario supported, if so what am i doing wrong , else any tips on how to implement it? I am using the latest Q2 version and WPF 4 / VS 2010.
Thanks!

Full code (couldn't find how to properly paste code on forums , any tips most welcome):

XAML :

<

 

 

Window x:Class="RadControlsWpfApp1.MainWindow"

 

 

 

 

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

 

 

 

 

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

 

 

 

 

xmlns:Tree="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"

 

 

 

 

Title="MainWindow" Height="350" Width="525">

 

 

 

 

 

<Grid>

 

 

 

 

 

<!--If you uncomment the line , autoexpand works just fine-->

 

 

 

 

 

<Tree:RadTreeView ItemsSource="{Binding Items}"

 

 

 

 

IsLoadOnDemandEnabled="True"

 

 

 

 

LoadOnDemand="RadTreeView_LoadOnDemand"

 

 

 

 

IsDragDropEnabled="True">

 

 

 

 

 

<Tree:RadTreeView.ItemTemplate>

 

 

 

 

 

<HierarchicalDataTemplate ItemsSource="{Binding Children}">

 

 

 

 

 

<TextBlock Text="{Binding Name}"></TextBlock>

 

 

 

 

 

</HierarchicalDataTemplate>

 

 

 

 

 

</Tree:RadTreeView.ItemTemplate>

 

 

 

 

 

</Tree:RadTreeView>

 

 

 

 

 

</Grid>

 

</

 

 

 

Window>

 

 


Code behind:

using

 

 

System;

 

 

using

 

 

System.Collections.Generic;

 

 

using

 

 

System.Windows;

 

 

using

 

 

System.Windows.Navigation;

 

 

using

 

 

Telerik.Windows.Controls;

 

 

using

 

 

System.ComponentModel;

 

 

namespace

 

 

RadControlsWpfApp1

 

{

 

 

 

public partial class MainWindow : Window

 

 

{

 

 

public MainWindow()

 

{

InitializeComponent();

 

 

 

this.DataContext = this;

 

Items =

 

 

new List<object>(){

 

 

 

 

new Item{Id = 1 , Name = "1"},

 

 

 

 

new Item{Id = 2 , Name = "2"},

 

 

 

 

new Item{Id = 3 , Name = "3"},

 

 

 

 

new Item{Id = 4 , Name = "4"},

 

 

 

 

new Item{Id = 5 , Name = "5"}

 

};

}

 

 

 

public List<object> Items { get; set; }

 

 

 

 

private void RadTreeView_LoadOnDemand(object sender, Telerik.Windows.RadRoutedEventArgs e)

 

{

 

 

 

RadTreeViewItem item = e.OriginalSource as RadTreeViewItem;

 

 

 

 

var Current = item.Item as Item;

 

Current.Children =

 

 

new List<object>(){

 

 

 

 

new Item{Id = 1 , Name = "1"},

 

 

 

 

new Item{Id = 2 , Name = "2"},

 

 

 

 

new Item{Id = 3 , Name = "3"},

 

 

 

 

new Item{Id = 4 , Name = "4"},

 

 

 

 

new Item{Id = 5 , Name = "5"}

 

};

item.IsLoadingOnDemand =

 

 

false;

 

}

}

 

 

 

public class Item : INotifyPropertyChanged

 

 

{

 

 

public int Id { get; set; }

 

 

 

 

public string Name { get; set; }

 

 

 

 

List<object> children = new List<object>();

 

 

 

 

public List<object> Children

 

{

 

 

 

get

 

 

{

 

 

return children;

 

}

 

 

 

set

 

 

{

children =

 

value;

 

PropertyChange(

 

 

"Children");

 

}

}

 

 

 

 

public event PropertyChangedEventHandler PropertyChanged = (a, b) => { };

 

 

 

 

public void PropertyChange(string propertyName)

 

{

 

 

 

this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));

 

}

}

}

 

1 Answer, 1 is accepted

Sort by
0
Miroslav
Telerik team
answered on 21 Jul 2010, 07:43 PM
Hi Jean-Christophe,

The issue with the non-working auto-expand when LoadOnDemand is enabled is a bug and it will be fixed in this week's internal build and any release after that.

The other unexpected thing in your case is the TreeViewItem expanding when something is dropped into it is a behavior of the TreeView. It assumes that any new items added to an item that is in the process of loading its children are in fact its loaded children. This does not work very well in this case but changing it will be a breaking change for some people and we are yet unsure if it should be done.

In this case the workaround is to store any dropped items while the children are loading and them append them after loading is complete. I have modified your project to do this. Also it uses updated assemblies where the first issue is fixed.   

Thanks for bringing our attention to this particular case.

Your Telerik Points have been updated for your feedback.

All the best,
Miroslav
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
Tags
TreeView
Asked by
Jean-Christophe DESIRE
Top achievements
Rank 1
Answers by
Miroslav
Telerik team
Share this question
or