0

I'm stuck with a problem I can't seem to get around...

I need to set the contents of a ScrollViewer to that of another (which contains a StackPanel, which contains images and text).

I have tried the following approaches and I keep getting an error ("The parameter is incorrect").

scrollViewer[1].Content = scrollViewer[2].Content; 

and

scrollViewer[1].Content = stackPanel[2];  // stackPanel[2] is currently what the content of scrollViewer[2] is set to 

I have also tried removing scrollViewer[1] as a child of the ContentPanel and creating a new instance of it, then adding it.

I have also tried setting scrollViewer[1].Content to null before setting it to anything else.

Does anyone know a way around this? What am I missing? Any clues would be appreciated!

1 Answers1

0

You might have to use a StackPanel as the Content of your ScrollViewers and then work with the Children property of the StackPanels, transfering controls between the two.

        <ScrollViewer x:Name="MyScrollViewer">
            <StackPanel x:Name="MyStackPanel">
            <Button x:Name="MyButton" Content="My Button"/>
            </StackPanel>
        </ScrollViewer>
        <ScrollViewer x:Name="MyScrollViewer2">
            <StackPanel x:Name="MyStackPanel2">
            </StackPanel>
        </ScrollViewer>

        UIElement currentElement = MyStackPanel.Children[0];

        MyStackPanel.Children.Remove(currentElement);

        MyStackPanel2.Children.Add(currentElement);

Hope this helps.

Paul Diston
  • 3,279
  • 1
  • 17
  • 20