2016-10-24 4 views
0

Я пытаюсь разработать древнюю форму шахмат, Чатураджи, как задание для школы. У меня есть очень простая настройка xaml, которая должна позволить мне перетаскивать элемент изображения внутри сетки.Событие падения не стреляет по сетке wpf

<Page 
    x:Class="Projectg.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:Projectg" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d"> 

    <Grid AllowDrop="True" Background="Transparent"> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition> 
      </ColumnDefinition> 
      <ColumnDefinition Width="900"> 
      </ColumnDefinition> 
      <ColumnDefinition> 
      </ColumnDefinition> 
     </Grid.ColumnDefinitions> 
     <Grid.RowDefinitions> 
      <RowDefinition></RowDefinition> 
      <RowDefinition Height="900"></RowDefinition> 
      <RowDefinition></RowDefinition> 
     </Grid.RowDefinitions> 
     <Grid Background="Transparent" x:Name="grdGrid" AllowDrop="True" Grid.Column="1" Grid.Row="1" Drop="grdGrid_Drop" > 
      <Grid.RowDefinitions> 
       <RowDefinition Height="*" /> 
       <RowDefinition Height="*" /> 
       <RowDefinition Height="*" /> 
       <RowDefinition Height="*" /> 
       <RowDefinition Height="*" /> 
       <RowDefinition Height="*" /> 
       <RowDefinition Height="*" /> 
       <RowDefinition Height="*" /> 

      </Grid.RowDefinitions> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="*" /> 
       <ColumnDefinition Width="*" /> 
       <ColumnDefinition Width="*" /> 
       <ColumnDefinition Width="*" /> 
       <ColumnDefinition Width="*" /> 
       <ColumnDefinition Width="*" /> 
       <ColumnDefinition Width="*" /> 
       <ColumnDefinition Width="*" /> 
      </Grid.ColumnDefinitions> 
      <Image CanDrag="True" x:Name="Image" Canvas.ZIndex="1" Height="80" Width="80" Grid.Row="0" Grid.Column="0" Source="/images/boat.png" DragStarting="Boat_DragStarting" Drop="Boat_Drop" DragOver="Image_DragOver" ></Image> 
      <Image CanDrag="True" Canvas.ZIndex="1" Height="80" Width="80" Grid.Row="1" Grid.Column="0" Source="/images/horse.png" ></Image> 
      <Image Canvas.ZIndex="1" Height="80" Width="80" Grid.Row="2" Grid.Column="0" Source="/images/elephant.png" ></Image> 
      <Image Canvas.ZIndex="1" Height="80" Width="80" Grid.Row="3" Grid.Column="0" Source="/images/crown.png" ></Image> 

      <Image Canvas.ZIndex="1" Height="80" Width="80" Grid.Row="0" Grid.Column="1" Source="/images/pawn.png" ></Image> 
      <Image Canvas.ZIndex="1" Height="80" Width="80" Grid.Row="1" Grid.Column="1" Source="/images/pawn.png" ></Image> 
      <Image Canvas.ZIndex="1" Height="80" Width="80" Grid.Row="2" Grid.Column="1" Source="/images/pawn.png" ></Image> 
      <Image Canvas.ZIndex="1" Height="80" Width="80" Grid.Row="3" Grid.Column="1" Source="/images/pawn.png" ></Image> 


     </Grid> 

    </Grid> 
</Page> 

При попытке перетащить изображение по сетке мыши показывает «DROP не допускается» курсор и отпуская изображение не срабатывает событие падения. Я спросил учителя об этом, и она сказала, что это, вероятно, потому, что я не задавал предпосылки для моей сетки.

Я быстро обновил код, но не повезло, событие все равно не срабатывало. Она действительно не знала, что происходит, и сказала, чтобы я отправил ей письмо, если проблема не исчезла.

Я думал, что сначала спрошу здесь.

Заранее благодарим за любую помощь.

+0

Попробуйте обработку DragOver и/или DragEnter и установка 'e.Effects' в обработчике (с). –

+0

Привет, событие DragOver срабатывает. Если это то, о чем вы спрашиваете? –

+0

Попробуйте 'IsHitTestVisible =" True "' на 'Grid' также. В противном случае он не будет получать сообщения мыши. Я забыл об этом. –

ответ

0

Быстрый взгляд на MSDN UWP Drag and Drop page предполагает, что вам необходимо обработать событие DragOver и указать, какие операции по удалению будет принимать элемент управления (true в любых формах Winamp XAML и IIRC и т. Д.). В UWP, это свойство AccepttedOperation на объект в арг событий (WPF называет это свойство Effects и это другой тип перечисления):

private void Grid_DragOver(object sender, DragEventArgs e) 
{ 
    e.AcceptedOperation = DataPackageOperation.Copy; 
} 
Смежные вопросы