Hi,
Could you please provide sample c# code (no xaml) to create a drapdown source & target for some ui element say ellipse?
Thanks
Babu
Hello babuumg,
Here is some code sample that can be used for your scenario. Lets assume that this is the used XAML:
<Grid x:Name="LayoutRoot"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions>
<Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions>
<ComboBox Grid.Column="0" x:Name="dropDown" SelectedIndex="0" Width="200"> <ComboBoxItem Content="Combo Item1"/> <ComboBoxItem Content="Combo Item2"/> <ComboBoxItem Content="Combo Item3"/> </ComboBox>
<Ellipse Grid.Column="1" Grid.RowSpan="2" x:Name="shapeElement" Fill="Beige" Stroke="Blue" StrokeThickness="1" Width="200" Height="150"/>
</Grid>
[Code behind]
private void PageLoaded(object sender, RoutedEventArgs e) { DropTarget dropTarget = new DropTarget { IsDropTarget = true }; DragDropManager.SetDropTarget(this.shapeElement, dropTarget);
foreach (ComboBoxItem item in this.dropDown.Items) { DragSource dragSource = new DragSource { IsDraggable = true, DataObject = item.Content }; dragSource.Drop += this.OnDrop; DragDropManager.SetDragSource(item, dragSource); } }
private void OnDrop(object sender, DropEventArgs e) { // get the data related to current operation object dataObject = e.Data; }
Here I use the Loaded event handler to set items that can be dragged and the drop target. When you drop dragged item onto target Drop event is fired. You can process and deal with your operation dependant data when OnDrop event handler is called. I hope that will help you. I'll be at your avail If you have any additional questions .
Best regards.
PPilev.