I’m trying to create a user control that has a Grid with two rows.
the first row for a title and the second one for a content that will be defined outside the user control such as a Button in our example.
Somehow I didn’t get it to work.
UserControl1 xaml:
<Grid Background="LightBlue">
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Text="Title" FontSize="30" Margin="10,0,0,0"/>
</Grid>
MainWindow xaml:
<Grid>
<local:UserControl1>
<Button>Click me</Button>
</local:UserControl1>
</Grid>
The picture below should explain what’s my problem:

The following code
Means that you set
UserControl1‘s Content property to be that button. This button simply replaces thatUserControls1‘s markup. So all the things that you have in UserControl1.xaml are not there any more.EDIT
If you want your UserControl to host some markup that will be set somewhere outside of it, you can add a
DependencyPropertyto it, for example:And add some element to it’s markup to host that additional content. Here’s an example extending the markup you provided:
Now you can use it as following: