I'm trying to put together a simple example. I am tring to drag a button onto one of two grids inside of a larger grid.
I created a DraggableButton class and a DropTargetGrid class along the lines described in the Draft "Getting Started" document.
I'm running into a Null Reference error during initialization. The DropTargetGrid seems to initialize, but the DraggableButton chokes and I'm not sure why. It compiles, but chokes on initialization.
Here is my implementation for the DraggableButton class:
Any ideas why this blows initialization?
Specifically this is the error I get:
{System.Windows.Markup.XamlParseException: System.NullReferenceException: Object reference not set to an instance of an object.
at Telerik.Windows.Controls.DragDrop.RadDragAndDropManager.Initialize()
at Telerik.Windows.Controls.DragDrop.RadDragAndDropManager.OnAllowDragChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object newValue, Object oldValue)
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isSetByStyle, Boolean isSetByBuiltInStyle)
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value)
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
at Telerik.Windows.Controls.DragDrop.RadDragAndDropManager.SetAllowDrag(DependencyObject obj, Boolean value)
at SimpleDragPOC.DraggableButton..ctor() [Line: 0 Position: 0]
--- Inner Exception ---
Object reference not set to an instance of an object.
---> System.NullReferenceException: Object reference not set to an instance of an object.
at Telerik.Windows.Controls.DragDrop.RadDragAndDropManager.Initialize()
at Telerik.Windows.Controls.DragDrop.RadDragAndDropManager.OnAllowDragChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object newValue, Object oldValue)
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isSetByStyle, Boolean isSetByBuiltInStyle)
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value)
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
at Telerik.Windows.Controls.DragDrop.RadDragAndDropManager.SetAllowDrag(DependencyObject obj, Boolean value)
at SimpleDragPOC.DraggableButton..ctor()
--- End of inner exception stack trace ---
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at SimpleDragPOC.Page.InitializeComponent()
at SimpleDragPOC.Page..ctor()}
I created a DraggableButton class and a DropTargetGrid class along the lines described in the Draft "Getting Started" document.
I'm running into a Null Reference error during initialization. The DropTargetGrid seems to initialize, but the DraggableButton chokes and I'm not sure why. It compiles, but chokes on initialization.
Here is my implementation for the DraggableButton class:
using System; | |
using System.Windows.Controls; | |
using System.Windows.Shapes; | |
using Telerik.Windows; | |
using Telerik.Windows.Controls.DragDrop; | |
namespace SimpleDragPOC | |
{ | |
public class DraggableButton : Button | |
{ | |
public event EventHandler<DragDropQueryEventArgs> DropQuery | |
{ | |
add | |
{ | |
this.AddHandler(RadDragAndDropManager.DropQueryEvent, value); | |
} | |
remove | |
{ | |
this.RemoveHandler(RadDragAndDropManager.DropQueryEvent, value); | |
} | |
} | |
public event EventHandler<DragDropEventArgs> DropInfo | |
{ | |
add | |
{ | |
this.AddHandler(RadDragAndDropManager.DropInfoEvent, value); | |
} | |
remove | |
{ | |
this.RemoveHandler(RadDragAndDropManager.DropInfoEvent, value); | |
} | |
} | |
public event EventHandler<DragDropQueryEventArgs> DragQuery | |
{ | |
add | |
{ | |
this.AddHandler(RadDragAndDropManager.DragQueryEvent, value); | |
} | |
remove | |
{ | |
this.RemoveHandler(RadDragAndDropManager.DragQueryEvent, value); | |
} | |
} | |
public event EventHandler<DragDropEventArgs> DragInfo | |
{ | |
add | |
{ | |
this.AddHandler(RadDragAndDropManager.DragInfoEvent, value); | |
} | |
remove | |
{ | |
this.RemoveHandler(RadDragAndDropManager.DragInfoEvent, value); | |
} | |
} | |
public DraggableButton() | |
{ | |
this.DragQuery += new EventHandler<DragDropQueryEventArgs>(DraggableButton_DragQuery); | |
this.DragInfo += new EventHandler<DragDropEventArgs>(DraggableButton_DragInfo); | |
this.DropQuery += new EventHandler<DragDropQueryEventArgs>(DraggableButton_DropQuery); | |
this.DropInfo += new EventHandler<DragDropEventArgs>(DraggableButton_DropInfo); | |
RadDragAndDropManager.SetAllowDrag(this, true); | |
} | |
void DraggableButton_DropInfo(object sender, DragDropEventArgs e) | |
{ | |
throw new NotImplementedException(); | |
} | |
void DraggableButton_DropQuery(object sender, DragDropQueryEventArgs e) | |
{ | |
throw new NotImplementedException(); | |
} | |
void DraggableButton_DragInfo(object sender, DragDropEventArgs e) | |
{ | |
// Drag has completed successfully | |
if (e.Options.Status == DragStatus.DragComplete) | |
{ | |
e.Handled = true; | |
} | |
} | |
void DraggableButton_DragQuery(object sender, DragDropQueryEventArgs e) | |
{ | |
// An object is about the be dragged | |
if (e.Options.Status == DragStatus.DragQuery) | |
{ | |
e.Options.DragCue = RadDragAndDropManager.GenerateVisualCue(new Rectangle() { Width = 10, Height = 10 }); | |
// Set result to true | |
e.QueryResult = true; | |
e.Options.Payload = this; | |
e.Source = this; | |
e.Handled = true; | |
} | |
// Ask if it is OK to drop the target at the particular location | |
if (e.Options.Status == DragStatus.DropSourceQuery) | |
{ | |
e.QueryResult = false; | |
e.Handled = true; | |
} | |
} | |
} | |
} | |
Any ideas why this blows initialization?
Specifically this is the error I get:
{System.Windows.Markup.XamlParseException: System.NullReferenceException: Object reference not set to an instance of an object.
at Telerik.Windows.Controls.DragDrop.RadDragAndDropManager.Initialize()
at Telerik.Windows.Controls.DragDrop.RadDragAndDropManager.OnAllowDragChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object newValue, Object oldValue)
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isSetByStyle, Boolean isSetByBuiltInStyle)
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value)
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
at Telerik.Windows.Controls.DragDrop.RadDragAndDropManager.SetAllowDrag(DependencyObject obj, Boolean value)
at SimpleDragPOC.DraggableButton..ctor() [Line: 0 Position: 0]
--- Inner Exception ---
Object reference not set to an instance of an object.
---> System.NullReferenceException: Object reference not set to an instance of an object.
at Telerik.Windows.Controls.DragDrop.RadDragAndDropManager.Initialize()
at Telerik.Windows.Controls.DragDrop.RadDragAndDropManager.OnAllowDragChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object newValue, Object oldValue)
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isSetByStyle, Boolean isSetByBuiltInStyle)
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value)
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
at Telerik.Windows.Controls.DragDrop.RadDragAndDropManager.SetAllowDrag(DependencyObject obj, Boolean value)
at SimpleDragPOC.DraggableButton..ctor()
--- End of inner exception stack trace ---
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at SimpleDragPOC.Page.InitializeComponent()
at SimpleDragPOC.Page..ctor()}