Does anyone have an idea how I can disable Drag & Drop for all my TextBox Elements? I found something here, but that would need me to run a loop for all Elements.
C# is a programming language. WPF is a technology used to develop rich GUI applications using C# (or any other . NET language).
“WPF would be dead in 2022 because Microsoft doesn't need to be promoting non-mobile and non-cloud technology. But WPF might be alive in that sense if it's the best solution for fulfilling specific customer needs today. Therefore, having a hefty desktop application needs to run on Windows 7 PCs with IE 8.
Is WPF used anymore? Electron is also more progressive compared to UWP. However, some industries still rely on WPF concepts and tools like XAML MVVM to develop futuristic web, mobile, and desktop applications. None of Microsofts GUI frameworks ever really die.
WPF is used to build Windows client applications that run on Windows operating system. WPF uses XAML as its frontend language and C# as its backend languages. WPF was introduced as a part of . NET Framework 3.0 as the Windows library to build Windows client apps and the next generation of Windows Forms.
Use the following after InitializeComponent()
DataObject.AddCopyingHandler(textboxName, (sender, e) => { if (e.IsDragDrop) e.CancelCommand(); });
You can easily wrap what this article describes into a attached property/behaviours...
ie. TextBoxManager.AllowDrag="False" (For more information check out these 2 CodeProject articles - Drag and Drop Sample and Glass Effect Samplelink text)
Or try out the new Blend SDK's Behaviors
UPDATE
Personally I created a custom TextBox control that does not allow drag as follows:
/// <summary>
/// Represents a <see cref="TextBox"/> control that does not allow drag on its contents.
/// </summary>
public class NoDragTextBox:TextBox
{
/// <summary>
/// Initializes a new instance of the <see cref="NoDragTextBox"/> class.
/// </summary>
public NoDragTextBox()
{
DataObject.AddCopyingHandler(this, NoDragCopyingHandler);
}
private void NoDragCopyingHandler(object sender, DataObjectCopyingEventArgs e)
{
if (e.IsDragDrop)
{
e.CancelCommand();
}
}
}
Instead of using TextBox use local:NoDragTextBox where "local" being the alias to the location of the NoDragTextBox assembly. The same above logic also can be extended to prevent Copy/Paste on TextBox .
For more info check the reference to the above code at http://jigneshon.blogspot.be/2013/10/c-wpf-snippet-disabling-dragging-from.html
Create your owner user control ex MyTextBox: TextBox and override:
protected override void OnDragEnter(DragEventArgs e)
{
e.Handled = true;
}
protected override void OnDrop(DragEventArgs e)
{
e.Handled = true;
}
protected override void OnDragOver(DragEventArgs e)
{
e.Handled = true;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With