I have a user control that should serve as container and it looks like following:
<ContentControl ... >
<Grid>
<Rectangle RadiusX="8" RadiusY="8">
<Rectangle.Fill>
...
</Rectangle.Fill>
</Rectangle>
...
<ContentPresenter />
</Grid>
</ContentControl>
When I use it in a window, the contents of controls are replaced instead of put into ContentPresenter:
<XWpf2:MyContainer Margin="40">
<ListView Margin="16" />
</XWpf2:MyContainer>
What is the right approach, what is wrong here?
You set the
Contentto aGrid, then you overwrite theContentwith aListView. If you want that structure to be preserved you need to assign it as theContentControl.Template.Of course the same thing can be said about the
MyContainerif it is aUserControl, if you set theContentand then overwrite it with aListViewyour wholeContentControlwill be gone as well.