c# image margin behavior
When I set my image margin in run-time it acts strange, different then when I set it via xaml code.

I want the margin value to be (40, 16, 0, 0).

When I add it in run-time, my code is this:

            System.Windows.Controls.Image proba = new System.Windows.Controls.Image();
            ImageSource imageSource = GetSlidePart(PresentationDocument.Open(path, false), 0, "rId2");
            proba.Source = imageSource;
            proba.Width = 2245721 / 9525;
            proba.Height = 2286004 / 9525;
            proba.Margin = new Thickness(40, 16, 0, 0);
            gridName.Children.Add(proba);


But, when I add image in xaml, the code in cs is this:


            image1.Source = GetSlidePart(PresentationDocument.Open(path, false), 0, "rId2");

and the code in xaml is this:


    <Window x:Class="GetInfoFromPptxFile.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="720" Width="960">
    
    <Grid Name="gridName">
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="416,20,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
        <Image Height="150" HorizontalAlignment="Left" Margin="40,16,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="200" />
    </Grid>
    </Window>


When I run my program, image1 is exactly where I want it to be, and the image named proba is not. Why is this when I give them the same margin values?
c# image margin behavior
===

When I set my image margin in run-time it acts strange, different then when I set it via xaml code.

I want the margin value to be (40, 16, 0, 0).

When I add it in run-time, my code is this:

            System.Windows.Controls.Image proba = new System.Windows.Controls.Image();
            ImageSource imageSource = GetSlidePart(PresentationDocument.Open(path, false), 0, "rId2");
            proba.Source = imageSource;
            proba.Width = 2245721 / 9525;
            proba.Height = 2286004 / 9525;
            proba.Margin = new Thickness(40, 16, 0, 0);
            gridName.Children.Add(proba);


But, when I add image in xaml, the code in cs is this:


            image1.Source = GetSlidePart(PresentationDocument.Open(path, false), 0, "rId2");

and the code in xaml is this:


    <Window x:Class="GetInfoFromPptxFile.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="720" Width="960">
    
    <Grid Name="gridName">
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="416,20,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
        <Image Height="150" HorizontalAlignment="Left" Margin="40,16,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="200" />
    </Grid>
    </Window>


When I run my program, image1 is exactly where I want it to be, and the image named proba is not. Why is this when I give them the same margin values?