Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Dependency property is a property (not itself, but dependent on another, let’s say a XAML Binding property) which register another property.</p> <p>The dependecy property register the other binding property in the code behind by registering it. A example that is used in my project is as follows:</p> <pre><code>public static DependencyProperty ImageUri = DependencyProperty.Register("Source", typeof(BitmapImage), typeof(CustomImagePlaceHolder), new PropertyMetadata(null)); </code></pre> <p>In the above code the ImageUri, is a dependency property which register the Source, that is defined/declared inside generic.xaml (whatever not sure whether declared, defined or anything else) as follows:</p> <pre><code>..HorizontalAlignment="Center" VerticalAlignment="Center" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}" /&gt; </code></pre> <p>So here it is quite important that the template binding value in the XAML should be registered as dependency property in the code behind.</p> <p>So when we have defined in XAML that the Image Source should be template bind with Source, we have registered the same Source As a DependencyProperty.</p> <p>We have to say which type of dependency property is that, in above example the Source is the type of BitmapImage, so we have defined typeof(BitmapImage).</p> <p>Now the owner/parent of this dependency property is our customControlClass CustomImagePlaceHolder, and we have defined that again while registering.</p> <p>Now to set the value of depndency property, by using our properties as below:</p> <pre><code>public BitmapImage Source { get { string strURI = (string)GetValue(CustomImagePlaceHolder.ImageUri); return new BitmapImage(new Uri(strURI)); } set { SetValue(CustomImagePlaceHolder.ImageUri, value); } } </code></pre> <p>Now this is how it go, we set the value from our code behind or xaml to the source property defined above, and inturn it sets the value of the dependecy property ImageUri, which inturn sets the value in the template binding Source, as we have registered ImageUri as Source, that is presennt generic.xaml.</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