0

A way to shorten the record of the code below.

<local:MyUserControl>
   <local:MyUserControl.MyDependencyProperty>
         <local:MyOtherUserControl>
   </local:MyUserControl.MyDependencyProperty>
</local:MyUserControl>

I'd like to write this in one line:

<local:MyUserControl>
     <local:MyUserControl.MyDependencyProperty="(..) local:MyOtherUserControl" />
</local:MyUserControl>

Is any posible way to do this? I try using x:Type, DynamicResource, nothing work.

A.Klim
  • 29
  • 3
  • StaticResource would work, but you would have to declare the resource somewhere, so you'd even need more lines. Your first XAML snippet shows the correct way of declaring what you want. Why do it differently? – Clemens May 20 '19 at 11:13
  • Maybe you could write a MarkupExtension that returns a new instance of a class from its ProvideValue method. I'd take Clemens' advice, personally. You might use [`DefaultPropertyAttribute`](https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.defaultpropertyattribute?view=netframework-4.8) if that's appropriate. – 15ee8f99-57ff-4f92-890c-b56153 May 20 '19 at 14:00
  • Not sure if Ed means this, but you can give a dependency property an initial value where you define it. I think that would be inferior though. – Andy May 20 '19 at 17:35

0 Answers0