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

Drag cue ContextTemplate in C#?

5 Answers 91 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Ankit
Top achievements
Rank 1
Ankit asked on 01 Dec 2010, 09:39 AM
I want to change the datatemplate of the DragCue (I mean i want to change the image source of the image tag applied in datatemplate in XAML). I used the following event but it didn't help me out. please help ASAP.

      private void OnDragQuery(object sender, DragDropQueryEventArgs e)
        {
            cue = new ContentControl();
            e.QueryResult = true;
            cue.MouseUp += new MouseButtonEventHandler(cue_MouseUp);
           
            e.Options.DragCue = cue;

            ImageSource IMGSOURCE = new BitmapImage(new Uri("/Images/header_idea.png",UriKind.Relative));

            DataTemplate dt = new DataTemplate();
          
            FrameworkElementFactory ef = new FrameworkElementFactory(typeof(Image));
            ef.SetValue(Image.SourceProperty, IMGSOURCE);

            dt.VisualTree = ef;
            cue.ContentTemplate = dt;
                        
            e.Options.ArrowCue = RadDragAndDropManager.GenerateArrowCue();
            e.Handled = true;
        }

5 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 06 Dec 2010, 12:41 PM
Hi Ankit,

You may take a look at this help article for further reference on the right way to define your custom Drag Cue. 

Regards,
Maya
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
Ankit
Top achievements
Rank 1
answered on 07 Dec 2010, 10:46 AM
The main problem is that I want to add the DataTemplate in c#....plz help.....reply soon
0
Maya
Telerik team
answered on 07 Dec 2010, 06:25 PM
Hello Ankit,

In this case you may try to set the Image directly to the Content property of the ContentControl. 
 
Regards,
Maya
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
0
Ankit
Top achievements
Rank 1
answered on 19 Jan 2011, 06:34 AM

hello admin,
                i have pasted the OnDragQuery event of the drag and drop. the two lines of code in which i have given the datatemplate to the drag cue's content template is is fine enough. But the image source in the datatemplate in xaml is always static  and i' not able to bind the image source. So, instead of that i wanted to give the dragcue a new image in C#. It does work, but its not firing and triggering the mouse up event. please point out any mistake and please suggest anything new if this isn't the right way to do it. And please i don't want to use the binding, as it is not working properply. Suggest something in DEeail. In DETAIL please, or attach and perfect and suitable example..Thanks in advance. please its important

 

 

void OnDragQuery(object sender, DragDropQueryEventArgs e)
{
ContentControl dragCue = new ContentControl();
e.QueryResult =
true;
dragCue.MouseUp += new MouseButtonEventHandler(dragCue_MouseUp);

dragCue.ContentTemplate =
this.Resources["DragTemplate"] as DataTemplate;  //is fine,
e.Options.DragCue = dragCue;   // but has static image souce in xaml

 

 

//Image im = new Image();             //this commented code doesn't fire
//im.Width = 40;                     //the MouseUp event, when i        
//im.Height = 40;                     //don't give the     
//im.Source = new BitmapImage(new Uri(@"/Images/drive.png", UriKind.Relative));  //content template to it. want
//e.Options.DragCue = im;             // to use it to give dynamic image
                                     //source instead 
                                    // of above highlighted code.

e.Options.ArrowCue =
RadDragAndDropManager.GenerateArrowCue();
e.Handled =
true;

 

}

 

0
Tsvyatko
Telerik team
answered on 21 Jan 2011, 02:37 PM
Hello Ankit,

You cannot handle mouse events from the drag cue. I guess you want to do this to determine whether the drag completes or is canceled. You can do this by the e.options.status in the raddraganddropmaanger events (draqquery, draginfo, dropquery, dropinfo).

More information can be found here:
http://www.telerik.com/help/silverlight/raddraganddrop-getting-started-with-drag-and-drop.html
http://www.telerik.com/help/silverlight/raddraganddrop-events-overview.html
http://www.telerik.com/help/silverlight/raddragdrop-events-eventargs.html

Best wishes,
Tsvyatko
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
DragAndDrop
Asked by
Ankit
Top achievements
Rank 1
Answers by
Maya
Telerik team
Ankit
Top achievements
Rank 1
Tsvyatko
Telerik team
Share this question
or