Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I really don't see a reason to create a property that substitutes for the <code>DataContext</code></p> <p>The purpose of the <code>DataContext</code> is to refer to the actual data behind your control. Why would you create a 2nd property for one that already exists? To me that's like saying you want to rewrite the <code>IsReadOnly</code> property of a control so it reads <code>DisableEditing</code> - there's no purpose for it. </p> <p>And furthermore, why would you want tie it to your application layer? The whole point of WPF is to separate business/application logic from the UI, and what you are trying to do is tie the two together. Use WinForms if you want that behavior.</p> <p>If you want to be sure your <code>UserControl</code> is only used with a <code>User</code> DataContext, use a <code>DataTemplate</code>.</p> <pre><code>&lt;DataTemplate DataType="{x:Type local:User}"&gt; &lt;local:MyUserControl /&gt; &lt;!-- DataContext will be User --&gt; &lt;/DataTemplate&gt; &lt;!-- This will display a User object, but because of the DataTemplate it will draw it using your UserControl instead of the default User.ToString() --&gt; &lt;ContentControl Content="{Binding CurrentUser}" /&gt; </code></pre> <p>If you really want to ensure that your <code>UserControl</code> only receives a <code>User</code> object as the <code>DataContext</code>, do some kind of validation check on initialization that <code>this.DataContext</code> is a <code>User</code> object. Don't create some kind of custom property that people need to remember to bind anytime they want to use your control.</p>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    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