tags:

views:

22

answers:

0

Okay, so, I've got a Silverlight app, and I'm trying to move an image around on a grid. I found that I could use Grid.Column and Grid.Row in the XAML to place the image in it's initial place. It will place relative to the grid because I have the image inside the grid tags. When I try to do the transformation from the code behind using, "Grid.SetColumn(ImageName, 0);", it sets the column relative to the image, not relative to the original grid. I know I'm missing something. How do I solve this?

Here's the XAML:

  <Grid x:Name="GridName" ShowGridLines="True" Margin="0,0,-148,-118" Width="800" Height="600">
<Grid.RowDefinitions>
 <RowDefinition/>
 <RowDefinition/>
 <RowDefinition/>
 <RowDefinition/>
 <RowDefinition/>
 <RowDefinition/>
        </Grid.RowDefinitions>
<Grid.ColumnDefinitions>
 <ColumnDefinition/>
 <ColumnDefinition/>
 <ColumnDefinition/>
 <ColumnDefinition/>
 <ColumnDefinition/>
 <ColumnDefinition/>
        </Grid.ColumnDefinitions>
<Image x:Name="ImageName" Margin="8,0,7,0" Source="image.png" Stretch="Fill" Grid.Column="1" Grid.Row="1">
                <i:Interaction.Behaviors>
  <ei:MouseDragElementBehavior DragFinished="MouseDragElementBehavior_DragFinished"/>
 </i:Interaction.Behaviors>
            </Image>
    </Grid>

Here's the codebehind:

    private void MouseDragElementBehavior_DragFinished(object sender, MouseEventArgs e)
    {
        Grid.SetColumn(this.ImageName, 0);
        Grid.SetRow(this.ImageName, 0);
        ImageName.Visibility = Visibility.Visible;
    }