Да, объявите ContentControl
в XAML вашего UserControl
.
Сделайте так, чтобы он связывал свое свойство Content
с DependencyProperty
в коде вашего UserControl
.
Добавьте атрибут: [ContentProperty("Name_Of_Your_Dependency_Property")]
поверх вашего класса UserControl.
Тогда вы можете сделать именно так, как вы сделали в своем вопросе. Атрибут определяет свойство зависимости по умолчанию, поэтому вам не нужно указывать <custom:myControl1.MyDP>
.
Что-то вроде:
[ContentProperty("InnerContent")]
public class MyControl : UserControl
{
#region InnerContent
public FrameworkElement InnerContent
{
get { return (FrameworkElement)GetValue(InnerContentProperty); }
set { SetValue(InnerContentProperty, value); }
}
// Using a DependencyProperty as the backing store for InnerContent. This enables animation, styling, binding, etc...
public static readonly DependencyProperty InnerContentProperty =
DependencyProperty.Register("InnerContent", typeof(FrameworkElement), typeof(MyControl), new UIPropertyMetadata(null));
#endregion
}
<UserControl ...>
<ContentControl Content="{Binding InnerContent, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" />
</UserControl>