I am attempting to get the RadDragAndDrop manager working between two listboxes. I have used the sample code provided in the Examples solution as a guide. Basically the only difference between my code and the code in the example is the data being handled. I am getting a list of custom objects using WCF calls instead of hardcoding the list.
I have wired up all events as in the example, have put breakpoints on all of them, but they never fire. Here is a sample of the code:
Here is the XAML
I can't seem to get it to work.
The listboxes are within a grid (as you can see from the XAML. Is that a problem?
Thanks in advance for any help.
I have wired up all events as in the example, have put breakpoints on all of them, but they never fire. Here is a sample of the code:
public class DraggableListBox : ListBox |
{ |
Brush listBoxDefaultBrush; |
Brush listBoxDragPossible = new SolidColorBrush(Colors.Orange); |
public event EventHandler<DragDropQueryEventArgs> DragQuery |
{ |
add |
{ |
this.AddHandler(RadDragAndDropManager.DropQueryEvent, value); |
} |
remove |
{ |
this.RemoveHandler(RadDragAndDropManager.DragQueryEvent, value); |
} |
} |
public event EventHandler<DragDropQueryEventArgs> DropQuery |
{ |
add |
{ |
this.AddHandler(RadDragAndDropManager.DropQueryEvent, value); |
} |
remove |
{ |
this.RemoveHandler(RadDragAndDropManager.DropQueryEvent, value); |
} |
} |
public event EventHandler<DragDropEventArgs> DragInfo |
{ |
add |
{ |
this.AddHandler(RadDragAndDropManager.DragInfoEvent, value); |
} |
remove |
{ |
this.RemoveHandler(RadDragAndDropManager.DragInfoEvent, value); |
} |
} |
public event EventHandler<DragDropEventArgs> DropInfo |
{ |
add |
{ |
this.AddHandler(RadDragAndDropManager.DropInfoEvent, value); |
} |
remove |
{ |
this.RemoveHandler(RadDragAndDropManager.DropInfoEvent, value); |
} |
} |
public DraggableListBox() |
{ |
RadDragAndDropManager.SetAllowDrop(this, true); |
this.DragQuery += new EventHandler<DragDropQueryEventArgs>(OnDragQuery); |
this.DragInfo += new EventHandler<DragDropEventArgs>(OnDragInfo); |
this.DropQuery += new EventHandler<DragDropQueryEventArgs>(OnDropQuery); |
this.DropInfo += new EventHandler<DragDropEventArgs>(OnDropInfo); |
} |
public override void OnApplyTemplate() |
{ |
base.OnApplyTemplate(); |
listBoxDefaultBrush = BorderBrush; |
} |
void OnDropInfo(object sender, DragDropEventArgs e) |
{ |
DraggableListBox box = sender as DraggableListBox; |
IList<RuleDTO> itemsSource = box.ItemsSource as IList<RuleDTO>; |
RuleDTO payload = e.Options.Payload as RuleDTO; |
if (e.Options.Status == DragStatus.DropPossible) |
{ |
box.BorderBrush = listBoxDragPossible; |
} |
else |
{ |
box.BorderBrush = listBoxDefaultBrush; |
} |
if (e.Options.Status == DragStatus.DropComplete) |
{ |
if (!itemsSource.Contains(payload)) |
{ |
itemsSource.Add(payload); |
} |
} |
} |
void OnDropQuery(object sender, DragDropQueryEventArgs e) |
{ |
DraggableListBox box = sender as DraggableListBox; |
IList<RuleDTO> itemsSource = box.ItemsSource as IList<RuleDTO>; |
RuleDTO payload = e.Options.Payload as RuleDTO; |
e.QueryResult = payload != null && !itemsSource.Contains(payload); |
} |
void OnDragInfo(object sender, DragDropEventArgs e) |
{ |
DraggableListBox box = sender as DraggableListBox; |
IList<RuleDTO> itemsSource = box.ItemsSource as IList<RuleDTO>; |
RuleDTO payload = e.Options.Payload as RuleDTO; |
if (e.Options.Status == DragStatus.DragComplete) |
{ |
if (payload != null && itemsSource.Contains(payload)) |
{ |
itemsSource.Remove(payload); |
} |
} |
} |
protected virtual void OnDragQuery(object sender, DragDropQueryEventArgs e) |
{ |
DraggableListBox box = sender as DraggableListBox; |
e.QueryResult = true; |
if (e.Options.Status == DragStatus.DragQuery) |
{ |
e.Options.SourceCueHost = null; |
e.Options.Payload = box.SelectedItem; |
ContentControl cue = new ContentControl(); |
//cue.ContentTemplate = this.Resources["ApplicationDragTemplate"] as DataTemplate; |
cue.Content = box.SelectedItem; |
e.Options.DragCue = cue; |
e.Options.ArrowCue = RadDragAndDropManager.GenerateArrowCue(); |
} |
} |
protected override void PrepareContainerForItemOverride(DependencyObject element, object item) |
{ |
base.PrepareContainerForItemOverride(element, item); |
RadDragAndDropManager.SetAllowDrag(element, true); |
RadDragAndDropManager.SetAllowDrop(element, true); |
} |
protected override void ClearContainerForItemOverride(DependencyObject element, object item) |
{ |
base.ClearContainerForItemOverride(element, item); |
RadDragAndDropManager.SetAllowDrag(element, false); |
RadDragAndDropManager.SetAllowDrop(element, false); |
} |
} |
Here is the XAML
<local:DraggableListBox x:Name="lboAvailableRules" Grid.Column="1" Grid.Row="4" Grid.RowSpan="3" Margin="8,8,30,8"> |
<local:DraggableListBox.ItemContainerStyle> |
<Style TargetType="ListBoxItem"> |
<Setter Property="HorizontalAlignment" Value="Stretch"/> |
<Setter Property="HorizontalContentAlignment" Value="Stretch" /> |
<Setter Property="DragDrop:RadDragAndDropManager.AllowDrop" Value="True"/> |
<Setter Property="DragDrop:RadDragAndDropManager.AllowDrag" Value="True"/> |
</Style> |
</local:DraggableListBox.ItemContainerStyle> |
<local:DraggableListBox.ItemTemplate> |
<DataTemplate> |
<TextBlock Text="{Binding RuleName}" FontWeight="Bold" HorizontalAlignment="Left" /> |
</DataTemplate> |
</local:DraggableListBox.ItemTemplate> |
</local:DraggableListBox> |
<local:DraggableListBox x:Name="lboSelectedRules" Margin="8,8,30,8" Grid.Column="3" Grid.Row="4" Grid.RowSpan="3"> |
<local:DraggableListBox.ItemTemplate> |
<DataTemplate> |
<TextBlock Text="{Binding RuleName}" HorizontalAlignment="Center" /> |
</DataTemplate> |
</local:DraggableListBox.ItemTemplate> |
</local:DraggableListBox> |
I can't seem to get it to work.
The listboxes are within a grid (as you can see from the XAML. Is that a problem?
Thanks in advance for any help.