0

имеется программа в которой нужно с помощью перетаскивания изображений слева на правый план помещения создать некую карту. Перетаскивание я реализовать смог, но когда начинаю узнавать расположение курсора то у меня всё плывёт и появляется не на своих местах. Так же надо чтобы при изменении размера окна изображения не уходили со своих мест на плане. Скриншот программы

Последнее что я пробовал это

XAML

<Grid>
       <Grid.ColumnDefinitions>
           <ColumnDefinition Width="250"/>
           <ColumnDefinition Width="*"/>
       </Grid.ColumnDefinitions>
       <Grid.RowDefinitions>
           <RowDefinition Height="75"/>
           <RowDefinition Height="50"/>
           <RowDefinition Height="*"/>
           <RowDefinition Height="50"/>
       </Grid.RowDefinitions>
       <TextBlock Text="Служба соревнований" FontSize="30" Foreground="Gray" Grid.Row="0" Grid.ColumnSpan="2"></TextBlock>
       <TextBlock Text="План помещения" FontSize="20" Grid.Row="1" Grid.Column="1" Margin="10"></TextBlock>
       <Border BorderBrush="Gray" BorderThickness="1" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Grid.RowSpan="2" Margin="10"/>
       <Border BorderBrush="Gray" BorderThickness="1" Margin="10" Grid.Row="1" Grid.RowSpan="2">
           <ScrollViewer>
               <StackPanel Orientation="Vertical" x:Name="stackPanelPlaces" Margin="5">
           &lt;/StackPanel&gt;
       &lt;/ScrollViewer&gt;
   &lt;/Border&gt;
   &lt;StackPanel Grid.Row=&quot;3&quot; Orientation=&quot;Horizontal&quot; HorizontalAlignment=&quot;Center&quot; VerticalAlignment=&quot;Center&quot;&gt;
       &lt;Button Content=&quot;Отчистить&quot; Name=&quot;buttonClear&quot; Click=&quot;ButtonClear_Click&quot; Width=&quot;100&quot; Margin=&quot;5&quot; Height=&quot;25&quot;  &gt;&lt;/Button&gt;
       &lt;Button Content=&quot;Сохранить&quot; Name=&quot;buttonSave&quot; Click=&quot;ButtonSave_Click&quot; Width=&quot;100&quot; Margin=&quot;5&quot; Height=&quot;25&quot;  &gt;&lt;/Button&gt;
   &lt;/StackPanel&gt;

   &lt;DockPanel Grid.Column=&quot;1&quot; Grid.Row=&quot;2&quot; Margin=&quot;20,0,20,20&quot;&gt;
       &lt;Image Source=&quot;/WorldSkills;component/Images/BuildingPlan.jpg&quot; AllowDrop=&quot;True&quot; Drop=&quot;Image_Drop&quot; Name=&quot;imageMap&quot; &gt;&lt;/Image&gt;
   &lt;/DockPanel&gt;
   &lt;Grid x:Name=&quot;gridMap&quot; Grid.Column=&quot;1&quot; Grid.Row=&quot;2&quot; Margin=&quot;20,0,20,20&quot; Drop=&quot;Image_Drop&quot; AllowDrop=&quot;True&quot;&gt;

   &lt;/Grid&gt;

</Grid>

C#

private void Image_Drop(object sender, DragEventArgs e)
        {
            if (currentImage != null)
            {
                Image image = new Image();
                image.Source = currentImage;
                image.Width = 32;
                image.Height = 32;
                //var p = Mouse.GetPosition(null);
                //var t1 = Mouse.GetPosition(this);
                //var t = this.PointFromScreen(t1);
                System.Drawing.Point p = System.Windows.Forms.Cursor.Position;
                image.RenderTransform = new TranslateTransform { X = p.X, Y = p.Y };
                gridMap.Children.Add(image);
                System.Windows.Forms.MessageBox.Show(p.X + "-" + p.Y);
            }
    }

0 Answers0