简体   繁体   中英

multiple stackpanels in ScrollViewer Windows 8 XAML

I seem to be having a problem with adding multiple StackPanels in a ScrollViewer. I can add the first one and it displays the data I want but when I try to add the second StackPanel is fails and brings the error "Duplication assignment to the 'Content' property of the 'ScrollViewer' object"

My front end code is like below:

<ScrollViewer VerticalScrollBarVisibility="Visible"
                                    HorizontalScrollBarVisibility="Visible"
                                    ZoomMode="Disabled"
                                    Grid.Column="1"
                                    Grid.Row="2"
                                    HorizontalAlignment="Stretch"
                                    VerticalAlignment="Stretch">
            <StackPanel Style='{StaticResource BlueFirstStackPanel}'>

                <TextBlock Text='Facility Patient Number:'
                                     Style='{StaticResource TextBlockStyle}' />
                <TextBox Style='{StaticResource TextBoxStyle}' />
                <TextBlock Text='Patient Number:'
                                     Style='{StaticResource TextBlockStyle}' />
                <TextBox Style='{StaticResource TextBoxStyle}' />
                <TextBlock Text='Patient Support Number:'
                                     Style='{StaticResource TextBlockStyle}' />
                <TextBox Style='{StaticResource TextBoxStyle}' />
                <TextBlock Text='NHIF Number:'
                                     Style='{StaticResource TextBlockStyle}' />
                <TextBox Style='{StaticResource TextBoxStyle}' />

                <TextBlock Text='Patient National ID:'
                                     Style='{StaticResource TextBlockStyle}' />
                <TextBox Style='{StaticResource TextBoxStyle}' />

            </StackPanel>
</ScrollViewer>

My C# code for the code has this in it:

public sealed class ScrollViewer : ContentControl
        {
        }

And the above displays very well but when I add a second StackPanel it brings an error. Any help with this?

The ScrollViewer can only have one child control. Try wrapping both StackPanels in a Grid or another StackPanel:

        <ScrollViewer>

            <StackPanel x:Name="ScrollViewerChild">

                <StackPanel x:Name="StackPanel1">

                </StackPanel>

                <StackPanel x:Name="StackPanel2">

                </StackPanel>

            </StackPanel>

        </ScrollViewer>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM