Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create WPF usercontrol which contains placeholders for later usage
    text
    copied!<p>I'd better ask the question by example. Let's say I have UserControl and Window which uses this control.</p> <p>I would like to design this control (named MyControl) in such way (this is sci-fi syntax!):</p> <pre><code>&lt;Grid&gt; &lt;Button&gt;Just a button&lt;/Button&gt; &lt;PlaceHolder Name="place_holder/&gt; &lt;/Grid&gt; </code></pre> <p>and use in such ways when designing my Window:</p> <pre><code>&lt;MyControl/&gt; </code></pre> <p>or</p> <pre><code>&lt;MyControl&gt; &lt;place_holder&gt; &lt;Button&gt;Button 1&lt;/Button&gt; &lt;/place_holder&gt; &lt;/MyControl&gt; </code></pre> <p>or</p> <pre><code>&lt;MyControl&gt; &lt;place_holder&gt; &lt;Button&gt;Button 1&lt;/Button&gt; &lt;Button&gt;Button 2&lt;/Button&gt; &lt;/place_holder&gt; &lt;/MyControl&gt; </code></pre> <p>Of course I would like to have ability to add even more elements to MyControl in Window. So, in a way it should work as container (like Grid, StackPanel, and so on). The placement would be defined in UserControl (in this example after button "Just a button") but what to add (what elements) would be defined in Window (where UserControl -- MyControl -- is used).</p> <p><em>I hope this is clear what I would like to achieve. The key point is using XAML when designing Window, so my class should be no worse than other controls.</em></p> <p>Now, the big <strong>QUESTION</strong> is -- how to do it?</p> <p>Remarks: styling is out of scope. All I want to do is add any controls I want to MyControl when designing Window (not when designing MyControl).</p>
 

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