C# WPF - Custom Control drag and drop (Visual Studio style)











up vote
0
down vote

favorite












How do I make my Custom controls draggable and droppable on a grid let's say?



I want to drag a panel(custom control) and drop it somewhere on my screen, in the best case in a grid, for example how it's done in Visual Studio, you can grab the solution explorer let's say and drop it somewhere, but how exactly do I do that?










share|improve this question







New contributor




Krusto Stoianov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Possible duplicate of C# WPF - Resizable Usercontrol / Page (Grab and drag resizing)
    – ASh
    Nov 18 at 7:18










  • No, it is not a duplicate. The one is for resizable panels, and this one is for garbbing panels and dropping them in a grid
    – Krusto Stoianov
    Nov 18 at 10:42















up vote
0
down vote

favorite












How do I make my Custom controls draggable and droppable on a grid let's say?



I want to drag a panel(custom control) and drop it somewhere on my screen, in the best case in a grid, for example how it's done in Visual Studio, you can grab the solution explorer let's say and drop it somewhere, but how exactly do I do that?










share|improve this question







New contributor




Krusto Stoianov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Possible duplicate of C# WPF - Resizable Usercontrol / Page (Grab and drag resizing)
    – ASh
    Nov 18 at 7:18










  • No, it is not a duplicate. The one is for resizable panels, and this one is for garbbing panels and dropping them in a grid
    – Krusto Stoianov
    Nov 18 at 10:42













up vote
0
down vote

favorite









up vote
0
down vote

favorite











How do I make my Custom controls draggable and droppable on a grid let's say?



I want to drag a panel(custom control) and drop it somewhere on my screen, in the best case in a grid, for example how it's done in Visual Studio, you can grab the solution explorer let's say and drop it somewhere, but how exactly do I do that?










share|improve this question







New contributor




Krusto Stoianov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











How do I make my Custom controls draggable and droppable on a grid let's say?



I want to drag a panel(custom control) and drop it somewhere on my screen, in the best case in a grid, for example how it's done in Visual Studio, you can grab the solution explorer let's say and drop it somewhere, but how exactly do I do that?







c# wpf






share|improve this question







New contributor




Krusto Stoianov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Krusto Stoianov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Krusto Stoianov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 17 at 22:01









Krusto Stoianov

306




306




New contributor




Krusto Stoianov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Krusto Stoianov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Krusto Stoianov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Possible duplicate of C# WPF - Resizable Usercontrol / Page (Grab and drag resizing)
    – ASh
    Nov 18 at 7:18










  • No, it is not a duplicate. The one is for resizable panels, and this one is for garbbing panels and dropping them in a grid
    – Krusto Stoianov
    Nov 18 at 10:42


















  • Possible duplicate of C# WPF - Resizable Usercontrol / Page (Grab and drag resizing)
    – ASh
    Nov 18 at 7:18










  • No, it is not a duplicate. The one is for resizable panels, and this one is for garbbing panels and dropping them in a grid
    – Krusto Stoianov
    Nov 18 at 10:42
















Possible duplicate of C# WPF - Resizable Usercontrol / Page (Grab and drag resizing)
– ASh
Nov 18 at 7:18




Possible duplicate of C# WPF - Resizable Usercontrol / Page (Grab and drag resizing)
– ASh
Nov 18 at 7:18












No, it is not a duplicate. The one is for resizable panels, and this one is for garbbing panels and dropping them in a grid
– Krusto Stoianov
Nov 18 at 10:42




No, it is not a duplicate. The one is for resizable panels, and this one is for garbbing panels and dropping them in a grid
– Krusto Stoianov
Nov 18 at 10:42












2 Answers
2






active

oldest

votes

















up vote
0
down vote













what you are looking for is available on this thread



in coculsion:



public partial class Form1 : Form {
public Form1() {
InitializeComponent();

//drag n drop setup
this.AllowDrop = true;
this.DragEnter += new DragEventHandler(Form1_DragEnter);
this.DragDrop += new DragEventHandler(Form1_DragDrop);
}

//hovering over form with file
void Form1_DragEnter(object sender, DragEventArgs e) {
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
}

//relising file into the form
void Form1_DragDrop(object sender, DragEventArgs e) {
string files = (string)e.Data.GetData(DataFormats.FileDrop);
foreach (string file in files) Console.WriteLine(file);
}
}





share|improve this answer





















  • You didn't got me. I don't want to drag and drop files on my control. I want to be able to drag and drop that control, to be able to grab it and move it around the screen, and then drop it in another grid.
    – Krusto Stoianov
    Nov 18 at 10:39


















up vote
-1
down vote













You need to build your project and then it will be automatically available in the Toolbox when you are in the XAML designer. Just like the common controls.



For Drag and Drop at runtime look and the official WPF documentation. Also I suggest you look at the GongSolutions.WPF.DragDrop library in GitHub it is open source so you can see how they implemented it if the functionality it provides does not do what you want.






share|improve this answer























  • I mean something else. I want to be able to grab the custom control from my window and move it, and in the best case be able to drop it in another grid
    – Krusto Stoianov
    Nov 18 at 10:39










  • I updated my answer to point you to some solutions.
    – AlesD
    Nov 18 at 20:26











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Krusto Stoianov is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53355952%2fc-sharp-wpf-custom-control-drag-and-drop-visual-studio-style%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













what you are looking for is available on this thread



in coculsion:



public partial class Form1 : Form {
public Form1() {
InitializeComponent();

//drag n drop setup
this.AllowDrop = true;
this.DragEnter += new DragEventHandler(Form1_DragEnter);
this.DragDrop += new DragEventHandler(Form1_DragDrop);
}

//hovering over form with file
void Form1_DragEnter(object sender, DragEventArgs e) {
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
}

//relising file into the form
void Form1_DragDrop(object sender, DragEventArgs e) {
string files = (string)e.Data.GetData(DataFormats.FileDrop);
foreach (string file in files) Console.WriteLine(file);
}
}





share|improve this answer





















  • You didn't got me. I don't want to drag and drop files on my control. I want to be able to drag and drop that control, to be able to grab it and move it around the screen, and then drop it in another grid.
    – Krusto Stoianov
    Nov 18 at 10:39















up vote
0
down vote













what you are looking for is available on this thread



in coculsion:



public partial class Form1 : Form {
public Form1() {
InitializeComponent();

//drag n drop setup
this.AllowDrop = true;
this.DragEnter += new DragEventHandler(Form1_DragEnter);
this.DragDrop += new DragEventHandler(Form1_DragDrop);
}

//hovering over form with file
void Form1_DragEnter(object sender, DragEventArgs e) {
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
}

//relising file into the form
void Form1_DragDrop(object sender, DragEventArgs e) {
string files = (string)e.Data.GetData(DataFormats.FileDrop);
foreach (string file in files) Console.WriteLine(file);
}
}





share|improve this answer





















  • You didn't got me. I don't want to drag and drop files on my control. I want to be able to drag and drop that control, to be able to grab it and move it around the screen, and then drop it in another grid.
    – Krusto Stoianov
    Nov 18 at 10:39













up vote
0
down vote










up vote
0
down vote









what you are looking for is available on this thread



in coculsion:



public partial class Form1 : Form {
public Form1() {
InitializeComponent();

//drag n drop setup
this.AllowDrop = true;
this.DragEnter += new DragEventHandler(Form1_DragEnter);
this.DragDrop += new DragEventHandler(Form1_DragDrop);
}

//hovering over form with file
void Form1_DragEnter(object sender, DragEventArgs e) {
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
}

//relising file into the form
void Form1_DragDrop(object sender, DragEventArgs e) {
string files = (string)e.Data.GetData(DataFormats.FileDrop);
foreach (string file in files) Console.WriteLine(file);
}
}





share|improve this answer












what you are looking for is available on this thread



in coculsion:



public partial class Form1 : Form {
public Form1() {
InitializeComponent();

//drag n drop setup
this.AllowDrop = true;
this.DragEnter += new DragEventHandler(Form1_DragEnter);
this.DragDrop += new DragEventHandler(Form1_DragDrop);
}

//hovering over form with file
void Form1_DragEnter(object sender, DragEventArgs e) {
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
}

//relising file into the form
void Form1_DragDrop(object sender, DragEventArgs e) {
string files = (string)e.Data.GetData(DataFormats.FileDrop);
foreach (string file in files) Console.WriteLine(file);
}
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 17 at 22:12









the Wongfon Semicolon

4317




4317












  • You didn't got me. I don't want to drag and drop files on my control. I want to be able to drag and drop that control, to be able to grab it and move it around the screen, and then drop it in another grid.
    – Krusto Stoianov
    Nov 18 at 10:39


















  • You didn't got me. I don't want to drag and drop files on my control. I want to be able to drag and drop that control, to be able to grab it and move it around the screen, and then drop it in another grid.
    – Krusto Stoianov
    Nov 18 at 10:39
















You didn't got me. I don't want to drag and drop files on my control. I want to be able to drag and drop that control, to be able to grab it and move it around the screen, and then drop it in another grid.
– Krusto Stoianov
Nov 18 at 10:39




You didn't got me. I don't want to drag and drop files on my control. I want to be able to drag and drop that control, to be able to grab it and move it around the screen, and then drop it in another grid.
– Krusto Stoianov
Nov 18 at 10:39












up vote
-1
down vote













You need to build your project and then it will be automatically available in the Toolbox when you are in the XAML designer. Just like the common controls.



For Drag and Drop at runtime look and the official WPF documentation. Also I suggest you look at the GongSolutions.WPF.DragDrop library in GitHub it is open source so you can see how they implemented it if the functionality it provides does not do what you want.






share|improve this answer























  • I mean something else. I want to be able to grab the custom control from my window and move it, and in the best case be able to drop it in another grid
    – Krusto Stoianov
    Nov 18 at 10:39










  • I updated my answer to point you to some solutions.
    – AlesD
    Nov 18 at 20:26















up vote
-1
down vote













You need to build your project and then it will be automatically available in the Toolbox when you are in the XAML designer. Just like the common controls.



For Drag and Drop at runtime look and the official WPF documentation. Also I suggest you look at the GongSolutions.WPF.DragDrop library in GitHub it is open source so you can see how they implemented it if the functionality it provides does not do what you want.






share|improve this answer























  • I mean something else. I want to be able to grab the custom control from my window and move it, and in the best case be able to drop it in another grid
    – Krusto Stoianov
    Nov 18 at 10:39










  • I updated my answer to point you to some solutions.
    – AlesD
    Nov 18 at 20:26













up vote
-1
down vote










up vote
-1
down vote









You need to build your project and then it will be automatically available in the Toolbox when you are in the XAML designer. Just like the common controls.



For Drag and Drop at runtime look and the official WPF documentation. Also I suggest you look at the GongSolutions.WPF.DragDrop library in GitHub it is open source so you can see how they implemented it if the functionality it provides does not do what you want.






share|improve this answer














You need to build your project and then it will be automatically available in the Toolbox when you are in the XAML designer. Just like the common controls.



For Drag and Drop at runtime look and the official WPF documentation. Also I suggest you look at the GongSolutions.WPF.DragDrop library in GitHub it is open source so you can see how they implemented it if the functionality it provides does not do what you want.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 18 at 20:25

























answered Nov 17 at 22:11









AlesD

2,01827




2,01827












  • I mean something else. I want to be able to grab the custom control from my window and move it, and in the best case be able to drop it in another grid
    – Krusto Stoianov
    Nov 18 at 10:39










  • I updated my answer to point you to some solutions.
    – AlesD
    Nov 18 at 20:26


















  • I mean something else. I want to be able to grab the custom control from my window and move it, and in the best case be able to drop it in another grid
    – Krusto Stoianov
    Nov 18 at 10:39










  • I updated my answer to point you to some solutions.
    – AlesD
    Nov 18 at 20:26
















I mean something else. I want to be able to grab the custom control from my window and move it, and in the best case be able to drop it in another grid
– Krusto Stoianov
Nov 18 at 10:39




I mean something else. I want to be able to grab the custom control from my window and move it, and in the best case be able to drop it in another grid
– Krusto Stoianov
Nov 18 at 10:39












I updated my answer to point you to some solutions.
– AlesD
Nov 18 at 20:26




I updated my answer to point you to some solutions.
– AlesD
Nov 18 at 20:26










Krusto Stoianov is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















Krusto Stoianov is a new contributor. Be nice, and check out our Code of Conduct.













Krusto Stoianov is a new contributor. Be nice, and check out our Code of Conduct.












Krusto Stoianov is a new contributor. Be nice, and check out our Code of Conduct.















 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53355952%2fc-sharp-wpf-custom-control-drag-and-drop-visual-studio-style%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

If I really need a card on my start hand, how many mulligans make sense? [duplicate]

Alcedinidae

Can an atomic nucleus contain both particles and antiparticles? [duplicate]