fix drag and drop bug

This commit is contained in:
PeterZhong 2024-12-03 16:30:56 +08:00
parent f7125ef57d
commit f735e0f239
2 changed files with 27 additions and 24 deletions

View File

@ -50,17 +50,17 @@
<Border BorderBrush="#000000" BorderThickness="1" HorizontalAlignment="Right" Height="24" Width="202" VerticalAlignment="Top" IsEnabled="True" Margin="580,210,0,0" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"> <Border BorderBrush="#000000" BorderThickness="1" HorizontalAlignment="Right" Height="24" Width="202" VerticalAlignment="Top" IsEnabled="True" Margin="580,210,0,0" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}">
<ComboBox x:Name="BasemapChooser" HorizontalAlignment="Left" Height="24" Margin="9,-1,0,-1" VerticalAlignment="Top" Width="182" SelectionChanged="BasemapChooser_OnSelectionChanged" IsEnabled="True"/> <ComboBox x:Name="BasemapChooser" HorizontalAlignment="Left" Height="24" Margin="9,-1,0,-1" VerticalAlignment="Top" Width="182" SelectionChanged="BasemapChooser_OnSelectionChanged" IsEnabled="True"/>
</Border> </Border>
<ToolBar HorizontalAlignment="Left" Height="29" Margin="0,20,0,0" VerticalAlignment="Top" Width="361"> <!-- <ToolBar HorizontalAlignment="Left" Height="29" Margin="0,20,0,0" VerticalAlignment="Top" Width="361"> -->
<Button x:Name="Btn_Add_Shp" Height="32" Width="32" Click="Menu_OpenShp_Click"> <!-- <Button x:Name="Btn_Add_Shp" Height="32" Width="32" Click="Menu_OpenShp_Click"> -->
<Button.Background> <!-- <Button.Background> -->
<ImageBrush ImageSource="D:\01_Development\10_Visual_Studio_Project\GisDevelop\GisDevelop_Exp\GisDevelop_Exp\add.png"/> <!-- <ImageBrush ImageSource="D:\01_Development\10_Visual_Studio_Project\GisDevelop\GisDevelop_Exp\GisDevelop_Exp\add.png"/> -->
</Button.Background> <!-- </Button.Background> -->
</Button> <!-- </Button> -->
<Button x:Name="Btn_Add_Online" Height="32" Width="32" Click="Btn_Add_Online_OnClick"> <!-- <Button x:Name="Btn_Add_Online" Height="32" Width="32" Click="Btn_Add_Online_OnClick"> -->
<Button.Background> <!-- <Button.Background> -->
<ImageBrush ImageSource="D:\01_Development\10_Visual_Studio_Project\GisDevelop\GisDevelop_Exp\GisDevelop_Exp\online.png"/> <!-- <ImageBrush ImageSource="D:\01_Development\10_Visual_Studio_Project\GisDevelop\GisDevelop_Exp\GisDevelop_Exp\online.png"/> -->
</Button.Background> <!-- </Button.Background> -->
</Button> <!-- </Button> -->
</ToolBar> <!-- </ToolBar> -->
</Grid> </Grid>
</Window> </Window>

View File

@ -526,7 +526,7 @@ namespace GisDevelop_Exp
if (listBoxItem == null) return; if (listBoxItem == null) return;
DataObject dataObj = new DataObject(listBoxItem.Content as CheckBox); DataObject dataObj = new DataObject(listBoxItem.Content as CheckBox);
DragDrop.DoDragDrop(LayerListBox, dataObj, DragDropEffects.Move); DragDrop.DoDragDrop(LayerListBox, listBoxItem, DragDropEffects.Move);
} }
} }
@ -539,8 +539,9 @@ namespace GisDevelop_Exp
return; return;
} }
var sourcePerson = e.Data.GetData(typeof(CheckBox)) as CheckBox; var sourceItem = e.Data.GetData(typeof(ListBoxItem)) as ListBoxItem;
if (sourcePerson == null) // var sourcePerson = sourceItem.Content;
if (sourceItem == null)
{ {
return; return;
} }
@ -552,16 +553,16 @@ namespace GisDevelop_Exp
} }
var targetPerson = listBoxItem.Content as CheckBox; var targetPerson = listBoxItem.Content as CheckBox;
if (ReferenceEquals(targetPerson, sourcePerson)) if (ReferenceEquals(listBoxItem, sourceItem))
{ {
return; return;
} }
int targetIndex = LayerListBox.Items.IndexOf(targetPerson); int targetIndex = LayerListBox.Items.IndexOf(listBoxItem);
int sourceIndex = LayerListBox.Items.IndexOf(sourcePerson); int sourceIndex = LayerListBox.Items.IndexOf(sourceItem);
LayerListBox.Items.Remove(sourcePerson); LayerListBox.Items.Remove(sourceItem);
LayerListBox.Items.Insert(targetIndex, sourcePerson); LayerListBox.Items.Insert(targetIndex, sourceItem);
MoveLayer(sourcePerson.ToolTip as string,targetPerson.ToolTip as string); MoveLayer(sourceItem.ToolTip as string,listBoxItem.ToolTip as string);
} }
private void AddLayerNameToList() private void AddLayerNameToList()
@ -585,14 +586,16 @@ namespace GisDevelop_Exp
}; };
Console.WriteLine(pLayers[i].Name); Console.WriteLine(pLayers[i].Name);
cb.Content = pLayers[i].Name; cb.Content = pLayers[i].Name;
cb.ToolTip = pLayers[i].Name; cb.ToolTip = cb.Content;
cb.Name = pLayers[i].Name; cb.Name = pLayers[i].Name;
cb.IsChecked = true; cb.IsChecked = true;
cb.Focusable = false; cb.Focusable = false;
cb.Checked += new RoutedEventHandler(Checked_Layers_CheckBox); cb.Checked += new RoutedEventHandler(Checked_Layers_CheckBox);
cb.Unchecked += new RoutedEventHandler(UnChecked_Layers_CheckBox); cb.Unchecked += new RoutedEventHandler(UnChecked_Layers_CheckBox);
ListBoxItem listBoxItem = new ListBoxItem(); ListBoxItem listBoxItem = new ListBoxItem();
LayerListBox.Items.Add(cb); listBoxItem.Content = cb;
listBoxItem.ToolTip = pLayers[i].Name;
LayerListBox.Items.Add(listBoxItem);
} }
} }