C # WPF ajoute le contrôle à la fenêtre principale au moment de l'exécution

Sa un peu ridicule que je ne peux pas trouver une réponse simple à cette question.
Mon objectif est de fixer un nouveau contrôle de l'image, tandis que l'application est en cours d'exécution.

img = new System.Windows.Controls.Image();
img.Margin = new Thickness(200, 10, 0, 0);
img.Width = 32;
img.Height = 32;
img.Source = etc;

J'ai essayé de

this.AddChild(img);//says must be a single element
this.AddLogicalChild(img);//does nothing
this.AddVisualChild(img);//does nothing

Il n'a jamais été aussi difficile pour ajouter un élément de formulaire.
Comment puis-je il suffit de fixer ce nouvel élément de la fenêtre principale (pas un autre contrôle), de sorte qu'il s'affiche.

Résolu, j'ai nommé la grille principale, et à partir de là, j'ai pu accéder à la enfants de l'attribut et de la fonction ajouter

main.children.add(img);

<Window x:Class="Crysis_Menu.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded" AllowsTransparency="False" Background="White" Foreground="{x:Null}" WindowStyle="SingleBorderWindow">
    <Grid Name="main">
        <Button Content="Run" Height="23" HorizontalAlignment="Left" Margin="12,12,0,0" Name="btnRun" VerticalAlignment="Top" Width="151" Click="btnRun_Click" />
        <TextBox Height="259" HorizontalAlignment="Left" Margin="12,40,0,0" Name="tbStatus" VerticalAlignment="Top" Width="151" />
    </Grid>
</Window>

source d'informationauteur Drake | 2011-10-14