1
votes

I Have a user Control which Contains a ScrollPanel. And I want to bind the userControl's content property to the ScrollPanel.

So my xaml would look like:

<CustomControl>
    <StackPanel/>
</CustomControl>

and in my UserControl my ScrollPanel child is set to StackPanel.

1
Any given Visual Element can only have one parent - so this wouldn't be possilbe.Goblin

1 Answers

0
votes

Do you mean ScrollViewer?

You have to remove the content from the user control (so the content no longer has a visual parent), then reassign the content to the scroll viewer.

In code:

var scrollViewer = new ScrollViewer();

var content = userControl.Content;
userControl.Content = null;     // removes content from visual tree
scrollViewer.Content = content;  // reassign content

If there's a way to do this via a binding, I haven't figured it out yet, though the situation where I'm having to do this is slightly different from yours.