I’m trying to implement a usercontrol with dependency properties. Here is my question; i want to set a dependency property with layout child or children of my user control. Is it possible and how can it be done?
<custom:myControl1>
<Label>Controls</Label>
<Label>I want</Label>
<Label>to set</Label>
<Label>as the dependency property</Label>
<Button Content="Is it possible?" />
</custom:myControl1>
Yes, declare a
ContentControlin the XAML of yourUserControl.Make it bind its
Contentproperty to aDependencyPropertyon the code-behind of yourUserControl.Add the attribute:
[ContentProperty("Name_Of_Your_Dependency_Property")]on top of your UserControl class.Then you can do precisely as you did in your question. The attribute defines the default Dependency Property so that you dont have to specify
<custom:myControl1.MyDP>.Something like: