I have built the following control:
MyContentControl.xaml.cs:
public partial class MyContentControl : UserControl { public MyContentControl() { InitializeComponent(); } public static readonly DependencyProperty MyContentProperty = DependencyProperty.Register( "MyContent", typeof(object), typeof(MyContentControl), new PropertyMetadata(default(object))); public object MyContent { get { return (object) GetValue(MyContentProperty); } set { SetValue(MyContentProperty, value); } } } MyContentControl.xaml:
<UserControl x:Class="MyContentControl" x:Name="self" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Grid> <Border BorderBrush="Gray" BorderThickness="1"> <ContentPresenter Content="{Binding ElementName=self, Path=MyContent}"/> </Border> </Grid> </UserControl> And it can be used like this:
<controls:MyContentControl> <controls:MyContentControl.MyContent> <TextBox Text="Some text..."/> </controls:MyContentControl.MyContent> </controls:MyContentControl> What I would like to achieve is being able to use my control like this:
<controls:MyContentControl> <TextBox Text="Some text..."/> </controls:MyContentControl> I would like to define the inner content like I would e.g. for a StackPanel.
How can this be achieved?
Panel, can I have my own custom XAML?