Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I find that implementing a DependencyProperty often involves four parts:</p> <ul> <li>The DependencyProperty itself</li> <li>Property with get and set</li> <li>Static changed handler</li> <li>Instance change handler</li> </ul> <p>You can add a dependency property to a UserControl so that you can data bind to something in the DataContext where the UserControl is instantiated. For example you could add a property to a SoUserControl:</p> <pre><code> #region SampleProperty // Demo for SO 2424526 public static readonly DependencyProperty SamplePropertyProperty = DependencyProperty.Register("SampleProperty", typeof(int), typeof(SoUserControl), new PropertyMetadata(OnSamplePropertyChanged)); /// &lt;summary&gt; /// Demo for SO 2424526 /// Gets or sets dependency property. /// &lt;/summary&gt; public int SampleProperty { get { return (int)GetValue(SamplePropertyProperty); } set { SetValue(SamplePropertyProperty, value); } } /// &lt;summary&gt; /// Handld changes to SamplePropertyProperty by calling a handler in the associated object. /// &lt;/summary&gt; /// &lt;param name="obj"&gt;object the property is associated with&lt;/param&gt; /// &lt;param name="e"&gt;details of change&lt;/param&gt; static void OnSamplePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) { (obj as SoUserControl).OnSamplePropertyChanged(e); } /// &lt;summary&gt; /// Handle changes to the SamplePropertyProperty dependency property. /// &lt;/summary&gt; /// &lt;param name="e"&gt;details of change&lt;/param&gt; private void OnSamplePropertyChanged(DependencyPropertyChangedEventArgs e) { int SamplePropertyNewValue = (int)e.NewValue; // do something with the internal logic of the control } #endregion </code></pre>
    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. 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