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

Binding TreeViewDragCue ToolTip

1 Answer 29 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 13 May 2011, 04:16 PM
Good morning,

How can I bind the ToolTipPreviwItem in the TreeViewDragCue ?

Because when I select items in my TreeView the TreeViewDragCue ToolTip displays the object name. (namespace.namespace2....Object)

Regards,
S

PS : I am not able to download .zip. Please post a code sample if needed

1 Answer, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 18 May 2011, 01:37 PM
Hi Steven,

You can define a custom DragCueTemplate and use it in the DropInfo event handler of  the RadDragAndDropManager. This technique is realized in the code snippets below. Please give it a try and let us know if it fits in your scenario.
XAML:
<UserControl.Resources>
        <DataTemplate x:Key="DragCueTemplate">
            <StackPanel Orientation="Vertical">
                <Rectangle Height="30" Fill="Transparent"></Rectangle>
                <TextBox Text="{Binding Name}" Height="20" Width="50" Background="AliceBlue" HorizontalAlignment="Left"></TextBox>
                <Rectangle Height="3" Fill="Transparent" HorizontalAlignment="Left"></Rectangle>
                <TextBlock Text="==> Drop SomeWhere" Height="20" />
            </StackPanel>
        </DataTemplate>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White">
        <telerik:RadTreeView x:Name="radTreeView" Width="300" IsDragDropEnabled="True" 
                             VerticalAlignment="Top" Background="Aqua" HorizontalAlignment="Left">
            <telerik:RadTreeView.ItemTemplate>
  
                <telerik:HierarchicalDataTemplate ItemsSource="{Binding Children}">
                    <TextBlock Text="{Binding Name}" />
                </telerik:HierarchicalDataTemplate>
  
            </telerik:RadTreeView.ItemTemplate>
  
        </telerik:RadTreeView>
    </Grid>
C#:
public partial class MainPage : UserControl
   {
       public MainPage()
       {
           InitializeComponent();
           radTreeView.AddHandler(RadDragAndDropManager.DragInfoEvent, new EventHandler<DragDropEventArgs>(OnDragInfo));
           radTreeView.ExpandAll();
           ObservableCollection<DataItem> rootCollection = new ObservableCollection<DataItem>();
           GenerateCollection(rootCollection, 4);
           radTreeView.ItemsSource = rootCollection;
           radTreeView.ExpandAll();
       }
       private void OnDragInfo(object sender, DragDropEventArgs e)
       {
           if (e.Options.Status == DragStatus.DragInProgress)
           {
               var draggedItem = e.Options.Source;
               // Create Drag Cue
               // 1. Create a ContentControl. It will be used as a DragCue.
               ContentControl dragCue = new ContentControl();
               // 2. Set the dragged item to the ContentControl's Content property.
               dragCue.Content = draggedItem.DataContext;
               // 3. Use a DataTemplate to "say" how the dragged item will be displayed.MessageBox.Show("ALO");
               dragCue.ContentTemplate = this.Resources["DragCueTemplate"] as DataTemplate;
               // 4. Set the ContentControl to the DragDropOptions' DragCue property.
               e.Options.DragCue = dragCue;
               // The other code follow here
           }
       }
       private void buttonExpand_Click(object sender, RoutedEventArgs e)
       {
           radTreeView.ExpandAll();
       }
       public void GenerateCollection(ObservableCollection<DataItem> rootCollection, int levels)
       {
           if (levels == 0)
           {
               return;
           }
           for (int i = 0; i < 3; i++)
           {
               DataItem item = new DataItem()
               {
                   Name = String.Format("Item " + i)
               };
               rootCollection.Add(item);
           }
           foreach (var dataitem in rootCollection)
           {
               GenerateCollection(dataitem.Children, levels - 1);
           }
       }        
   }
   public class DataItem
   {
       public string Name { get; set; }
       public ObservableCollection<DataItem> Children { get; set; }
       public DataItem()
       {
           this.Children = new ObservableCollection<DataItem>();
       }
   }


Greetings,
Petar Mladenov
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
Steven
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question
or