wpfcustom-controls

Passing objects to UserControl


I'm trying to create a CustomControl to which I can pass an "Person" object. How can I pass the person object to the custom control like this PersonDetails="{Binding Path=Person}" to the CusomControl ?

instead of passing Address="{Binding Path=Person.Address}"Address="{Binding Path=Person.FirstName}" ect


Solution

  • You have to declare PersonDetails as a dependency property.

    Then you can use it as any other WPF control property - both in XAML (including data binding) and in code.