6

I have a UserControl that I would like to be able to have more than one child. It already has StackPanel as it's child, so what am I doing wrong?

Ultimately, I'd like for the control to include some of its own children automatically and then, when it's used, allow placing more children inside one of its elements. I tried MSDN's How to Override the Logical Tree without success.

Thanks in advance.

LayerPanelItem.xaml:

<UserControl x:Class="Controls.LayerPanelItem" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <StackPanel></StackPanel> </UserControl> 

Main.xaml:

<controls:LayerPanelItem> <TextBlock>Test</TextBlock> <TextBlock>Test</TextBlock> <!-- Error: The property 'Content' is set more than once. --> </controls:LayerPanelItem> 

2 Answers 2

2

You can't do this (directly) with a UserControl. Instead, you'll need to derive from ItemsControl, and put your own custom layout logic in the subclass.

Sign up to request clarification or add additional context in comments.

1 Comment

Reed is correct. Here's why you can't do it: When the XAML in LayerPanelItem.xaml is processed, UserControl's Content property is set. So you are effectively trying to use Content for two different purposes.
-1

Try to add Grid in your UserControl and add rest of child to that grid.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.