Note that there are some explanatory texts on larger screens.

plurals
  1. POC# WPF add control to main window at run time
    text
    copied!<p>Its a bit ridiculous that I cant find a simple answer to this. My goal is to attach a new image control while the application is running.</p> <pre><code>img = new System.Windows.Controls.Image(); img.Margin = new Thickness(200, 10, 0, 0); img.Width = 32; img.Height = 32; img.Source = etc; </code></pre> <p>Ive tried </p> <pre><code>this.AddChild(img);// says must be a single element this.AddLogicalChild(img);// does nothing this.AddVisualChild(img);// does nothing </code></pre> <p>It was never this difficult to add a element with forms. How can I simply attach this new element to the main window (not another control) so that it will show up.</p> <p>Solved it, I named the grid main, and from there I was able to access the children attribute and the add function</p> <pre><code>main.children.add(img); &lt;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"&gt; &lt;Grid Name="main"&gt; &lt;Button Content="Run" Height="23" HorizontalAlignment="Left" Margin="12,12,0,0" Name="btnRun" VerticalAlignment="Top" Width="151" Click="btnRun_Click" /&gt; &lt;TextBox Height="259" HorizontalAlignment="Left" Margin="12,40,0,0" Name="tbStatus" VerticalAlignment="Top" Width="151" /&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload