简体   繁体   中英

XAML Vertically align only top stackpanel

I have a view that contains two stackpanels (main ones). The top one is a spinner and "One Moment Please..." that I need centered vertically. The bottom one appears when the top one disappears and I need it stretched so the content appears at the top of the window.

     <ScrollViewer VerticalScrollBarVisibility="Auto">
            <StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Center">
                <local:BusyIndicator VerticalAlignment="Center" HorizontalAlignment="Center" Width="50" Height="50" Visibility="{Binding Path=IsBusy, Converter={StaticResource booleanToVisibilityConverter}}"/>
                <TextBlock  VerticalAlignment="Center" HorizontalAlignment="Center" Text="One Moment Please" Visibility="{Binding Path=IsBusy, Converter={StaticResource booleanToVisibilityConverter}}"/>
                <StackPanel HorizontalAlignment="Center" Visibility="{Binding Path=HasError, Converter={StaticResource booleanToVisibilityConverter}}">
                    <TextBlock
                    Visibility="{Binding Path=HasError, Converter={StaticResource booleanToVisibilityConverter}}"
                    Text="{Binding Path=ErrorMessage}" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="12" TextWrapping="Wrap"/>
                </StackPanel>
                <StackPanel VerticalAlignment="Stretch" Orientation="Vertical" Visibility="{Binding Path=IsBusy, Converter={StaticResource inverseBooleanToVisibilityConverter}}">
</Stackpanel>
</ScrollViewer>

The issue that keeps happening is that the bottom stackpanel is vertically centered and the content does not move to the top of the window.

I apologize but I am not able to show the actual view (NDA). What I am trying to do (Right Image), what is happening (Left Image). NOTE: Only the text or the spinner show up at one time. I am not trying to align the two, just make the spinner center vertically when the text is not displayed.

在此处输入图片说明

Does your booleanToVisibilityConverter return Visibility.Collapsed or .Hidden for False? It should return Collapsed in order for the space to be reclaimed.

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