Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>IIRC, in the direct form you wrote, this is impossible to achieve, because in the Design Time you do not work with an instance of your control. Pay attention to the first lines of the XAML: the root element is specifying a UserControl, the base class. This is the instance you work with! This is why there were always been problems with designing components with abstract base classes. Everything you play in the designer with is a UserControl instance, filled with the content specified by XAML.</p> <p>The XAML parser instantiates any objects that are described by tag names. As your are designing your control, the parser is prevented from instantiating it, because the control actually does not exist yet. This is exactly why the first word of the XAML is UserControl and the your class name is given as x:Class attribute. When you save the XAML, it will get preprocessed to MyControl.g.cs file that specified a partial-class, it will get compiled along with pair with your own MyControl.cs, and only then the Visual Studio (or your app) will be able to invoke code that it contains.</p> <p>If you try hard, you may force the XAML parser to load your control, but what for? You will have a snapshot of PREVIOUS build, not the currently-edited one. Only XAML templates are kept up-to-date, because they are dynamically dropped and loaded.</p> <p>That's for the part "why did my constructor did not run".</p> <p>And if you need the Message to get set in ctor, why don't just set it as the default property value?</p> <pre><code>public sealed partial class SimpleBinding : UserControl { public static DependencyProperty MessageProperty = DependencyProperty.Register( "Message", typeof(String), typeof(SimpleBinding), new PropertyMetadata("Hello world")); ... public SimpleBinding() { this.InitializeComponent(); } } </code></pre> <p>Of course, it is heavily limited and hardcoded, in constrast to what you could branch/calculate/etc in the constructor. If you need more freedom, try playing with Design Time Data, maybe that will help a little.</p> <p>If you <strong>really</strong> need to run custom code inside your component at its own individual design time, consider moving the code into a dummy base class and put &lt;MyBaseClass&gt; instead of &lt;UserControl&gt; at the root of the XAML. The XAML parser will be forced to instantiate it and then skin it with the contents of xaml. Just be aware that you will invoke the previous successful build of that base class. Also, remember to use IsInDesignMode or similar (see ie. <a href="https://stackoverflow.com/a/426072/717732">https://stackoverflow.com/a/426072/717732</a>) for filtering the behaviour.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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