Telerik Forums
UI for WPF Forum
1 answer
15 views

Hi,

I tried to combine the 2 telerik examples related to RadTreeviews - the RadTreeView as File Explorer and that from SDK repo related to drag and drop between 2 Radtreeview.

I finally succeeded to make an working short program, but I don't know why by dragging a file from one tree to another, the UI of the second tree shows the dropped file twice - even the Tree ItemsSource is correct (only one file dragged and dropped)

after Puplating the trees,I used DragDropMAnager and the following classes (as they are defined in telerik example, adapted to files/folder structure)

DragDropManager.AddDragOverHandler(this.tree1, OnTree1DragOver, true);
DragDropManager.AddDragOverHandler(this.tree2, OnTree2DragOver, true);
DragDropManager.AddDropHandler(this.tree2, OnTree2Drop, true);

My OnTree2DragOver function:

var options = DragDropPayloadManager.GetDataFromObject(e.Data, TreeViewDragDropOptions.Key) as TreeViewDragDropOptions;
if (options == null)
    return;

// The condition after the first OR operator is needed to deny the drop of items in Application File. (sub-items)
RadTreeViewItem dropTargetItem = options.DropTargetItem;

var draggedItem = options.DraggedItems.First();
if (dropTargetItem == null ||
(dropTargetItem != null &&
     options.DropTargetItem.DataContext is File &&
     options.DropPosition == DropPosition.Inside) ||
    draggedItem is Folder)
{
    options.DropAction = DropAction.None;
}

options.UpdateDragVisual();

 

 

my OnTree2Drop function is:

 var options = DragDropPayloadManager.GetDataFromObject(e.Data, TreeViewDragDropOptions.Key) as TreeViewDragDropOptions;
 if (options == null)
     return;
 File draggedItem = options.DraggedItems.FirstOrDefault() as File;
 if (draggedItem == null)
     return;
 RadTreeViewItem dropTargetItem = options.DropTargetItem;
 if (dropTargetItem == null)
     return;
 var dropItemModel = dropTargetItem.DataContext;
 if (dropItemModel == null)
     return;
 var dropTree = sender as RadTreeView;
 if (dropTree != null)
 {
     // Disable drop in tree2 File.
     if (dropItemModel is File && options.DropAction == DropAction.None)
     {
         e.Handled = true;
         return;
     }
     //Drop in tree2
     if (dropItemModel is Folder || dropItemModel is File)
     {
         options.DropAction = DropAction.Copy;
         //options.UpdateDragVisual();
         Folder destinationFolder = null;
         if (dropItemModel is Folder)
         {
             // Dropping inside Application.
             destinationFolder = dropItemModel as Folder;
         }
         else
         {
             // Dropping Before or After an Application Resource.
             destinationFolder = options.DropTargetItem.ParentItem.DataContext as Folder;
         }
         if (destinationFolder == null)
         {
             return;
         }
         File file = new File()
         {
             Name = draggedItem.Name
         };
         destinationFolder.Items.Add(file);
    
         //options.UpdateDragVisual();
     
         System.IO.File.Copy(@draggedItem.FullPath, System.IO.Path.Combine(@destinationFolder.FullPath, System.IO.Path.GetFileName(@draggedItem.FullPath)));
         options.UpdateDragVisual();

My OnTree1DragOver:

var options = DragDropPayloadManager.GetDataFromObject(e.Data, TreeViewDragDropOptions.Key) as TreeViewDragDropOptions;
if (options != null)
{
    options.DropAction = DropAction.None;
    options.UpdateDragVisual();
    var draggedFile = options.DraggedItems.First() as File;
    e.Handled = true;
}

In the attached picture you'll see Adeliatte Italic.ttf twice, even I dragged and drpped it only once.

Could you please take a short look and tell me what I'm doing wrong?

Or, if it is not too much time consuming for you to come back with an example of 2 treeviews acting as explorer and with d&d functionality?

 

Thank you in advance for your support.

Danny

Danny
Top achievements
Rank 1
Iron
 answered on 14 Apr 2025
0 answers
49 views

I've been dealing with an issue for awhile now where dragging and dropping multiple tree items is kind of difficult.  If I select several items and then try to drag them somewhere else, it only works if I start the drag with my mouse over the last item selected.  If I try to start the drag with my mouse over any other selected items then the tree selection changed event fires and wipes out all of the selected items except for the one I'm currently over.

Holding the shift key during all of this also makes it work as expected.  But both of the ways that work aren't very obvious to users.  Is there any other way to keep all of the selected items when dragging regardless of what item the drag starts over?

 

Blaine
Top achievements
Rank 1
 asked on 02 Jan 2025
1 answer
65 views

Hello,

I use the RadTreeListView control and set the theme implicitly. So far, everything works well. Currently, I use the theme "Office Black". I would like to adjust the table by making changes to the "Telerik.Windows.Controls.GridView.xaml"-ResourceDictionary. So far, I could edit a lot of stuff, and it mostly worked great. But there's one thing I just can't seem to resolve.

I am having trouble customizing all the shown borders of the RadTreeListView. I don't want to have any "IsSelected" or "EditMode" Styles since my TreeListView should exclusively display information.

1) Header row cells:

I noticed that there seem to be several borders around each header row cell. What are the names of the colors of the borders or the names of the borders themselves? A black border, probably 1 pixel in thickness in each direction, keeps appearing and after hours of searching I still haven't found how to hide it / delete it from the ResourceDictionary. In the header row, each cell must only have one white border surrounding it - plain WPF :)

2) 'Normal' table cells showing content:

Furthermore, a border with 1 pixel thickness on the left and upper side appears as soon as I click into a cell (NOT in the header). As soon as clicked, the border mustn't change its style in any way - no change in style or behavior desired.

 

I want to edit the ResourceDictionary and NOT just overwrite the TreeListView itself. The ResourceDictionary must be reusable in my solution.

Thanks in advance! Any help is appreciated. 

Stenly
Telerik team
 answered on 20 Dec 2024
1 answer
37 views
I am working on an application that uses a DockingPanesFactory to add RadPanes to a window. These RadPanes have KeyTriggers that do not execute when floating. I understand that it is because it becomes a ToolWindow and therefore it is not in the same visual tree. How can I make sure tgatvmy key triggers get passed to the ToolWindow so the commands execute?
Martin Ivanov
Telerik team
 answered on 22 Nov 2024
1 answer
50 views

I want to expand a newly added item in RadTreeView so that the selection is visible. However, as the item is (obviously) not yet visible, the SelectedContainer is (and stays) null. As I am using HierarchicalDataTemplates to create the tree, I don't have the path of the newly created item - so I cannot use 'ExpandItemByPath' (or how can I get the Path for the selected item?).

So how can I find the parents of the recently created Item so that I could expand them?

Martin Ivanov
Telerik team
 answered on 04 Nov 2024
1 answer
73 views

Hello,

I would like to ask for your help. When creating RadTreeView my ItemContainerStyle is not working. I would like to connect ViewModel IsExpanded with RadTreeViewItem but I can't do it. The component works fine for me if I define a HierarchicalDataTemplate for the Item template as follows.


   <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
       <Grid.Resources>

             <HierarchicalDataTemplate x:Key="ItemTemplateTree"
                                       ItemsSource="{Binding Children}">
                 <StackPanel Orientation="Horizontal">
                     <TextBlock Text="{Binding Name}" FontWeight="Bold" />
                     <TextBlock Text="{Binding Value, StringFormat=': {0}'}" />
                 </StackPanel>
             </HierarchicalDataTemplate>
         </Grid.Resources>
 <telerik:RadTreeView  Name="JsonTreeView"
             ItemsSource="{Binding SelectedItemInContent.MediaTreeInfoJson}"
             IsVirtualizing="True"
             SelectionMode="Extended"
             ItemTemplate="{StaticResource ItemTemplateTree}"
            />

     </Grid>




 

But if I try to change the ItemContainerStyle like in the Demo examples "ShuttleControl_WPF", the whole tree disappears.  As if it doesn't have a properly defined Style.

 


<Style x:Key="nodeStyle" TargetType="telerik:RadTreeViewItem">
       <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
   </Style>

The model I use for Items is as follows:

 


 public class JsonInfoTreeModel: ViewModelBase
    {
        private string name;
        private string value;
        private ObservableCollection<JsonInfoTreeModel> children;
        private bool isExpanded;

        public JsonInfoTreeModel()
        {
            Children = new ObservableCollection<JsonInfoTreeModel>();
            IsExpanded = true;
        }

        public string Name
        {
            get { return name; }
            set
            {
                if (name != value)
                {
                    name = value;
                    OnPropertyChanged(nameof(Name));
                }
            }
        }

        public string Value
        {
            get { return value; }
            set
            {
                if (this.value != value)
                {
                    this.value = value;
                    OnPropertyChanged(nameof(Value));
                }
            }
        }

        public ObservableCollection<JsonInfoTreeModel> Children
        {
            get { return children; }
            set
            {
                if (children != value)
                {
                    children = value;
                    OnPropertyChanged(nameof(Children));
                }
            }
        }

        public bool IsExpanded
        {
            get { return isExpanded; }
            set
            {
                if (isExpanded != value)
                {
                    isExpanded = value;
                    OnPropertyChanged(nameof(IsExpanded));
                }
            }
        }
    }


Thank you for any help.

 

 

************** Update ****************

ExamleDesk.WPF.zip

 

 

Tadeáš
Top achievements
Rank 1
 updated question on 06 Aug 2024
1 answer
54 views

Is there a way to drag from a radtreeview control and get the drop event in a C++ Windows window.  We do get the event, but we do not know how to get access to the data.   Can we override the drag and drop and do our own implementation?

Mike

 

Martin Ivanov
Telerik team
 answered on 22 May 2024
1 answer
47 views
Which type of control can be used to create control as per image and How ? 
Dimitar
Telerik team
 answered on 25 Apr 2024
1 answer
62 views

I have a wpf radtreeview, now I can use left click to select item,

but i want to the selection behavior to be changed to double click, how could I achieve that?

Martin Ivanov
Telerik team
 answered on 16 Apr 2024
0 answers
141 views

Hi

I have the following datatemplate:

		<DataTemplate 
			x:Key="ReportComponentTemplate">
			<Grid>
				<Grid.RowDefinitions>
					<RowDefinition Height="*"/>
					<RowDefinition Height="30"/>
				</Grid.RowDefinitions>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="30"/>
					<ColumnDefinition Width="*"/>
				</Grid.ColumnDefinitions>
				<CheckBox IsChecked="{Binding Included}" Margin="5,0"/>
				<TextBlock
					Grid.Column="1" Text="{Binding Didascalia}" HorizontalAlignment="Stretch"
					TextWrapping="Wrap"/>
				<t:RadComboBox Grid.Row="1" Grid.ColumnSpan="2"
					Width="150"
					Visibility="{Binding DataContext.TemplatePath, 
						RelativeSource={RelativeSource AncestorType=local:TreeViewReportControl},
						Converter={StaticResource StringEmptyToHide}}"
					VerticalAlignment="Top" Margin="5,0"
					HorizontalAlignment="Left"
					ItemsSource="{Binding TagsDisponibili}"
					SelectedItem="{Binding TagSelezionato, NotifyOnTargetUpdated=True, Mode=TwoWay}">
					<i:Interaction.Triggers>
						<i:EventTrigger EventName="SelectionChanged">
							<i:InvokeCommandAction Command="{Binding DataContext.TagSelezionatoUpdatedCommand
								, RelativeSource={RelativeSource AncestorType=local:TreeViewReportControl}}"/>
						</i:EventTrigger>
					</i:Interaction.Triggers>
				</t:RadComboBox>
			</Grid>
		</DataTemplate>
This datatemplate is used as itemtemplate of a internal node of a radtreeview.
The Vsual tree is the following:

<t:RadDocking>
	<t:RadSplitContainer MaxWidth="600" t:DockingPanel.InitialSize="400,150" Name="LeftContainer" InitialPosition="DockedLeft">
		<t:RadPaneGroup>
			<t:RadPane>
				<Grid>
					<t:RadBusyIndicator>
						<t:RadTreeView>
						</t:RadTreeView>
					</t:RadBusyIndicator>
				</Grid>
			</t:RadPane>
		</t:RadPaneGroup>
	</t:RadSplitContainer>
</t:RadDocking>

Of course there are many other controls.
The strange here it is that textblock inside the row 1 of  ReportComponentTemplate systematically overflow the width of its parents.
I can set a fixed width or a maxwidth, but I want that it occupy the full available area (but not over).
Thank you
Luigi

Luigi
Top achievements
Rank 3
Bronze
Iron
Iron
 asked on 02 Apr 2024
Narrow your results
Selected tags
Tags
+? more
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?