简体   繁体   English

XAML仅垂直对齐顶部堆栈面板

[英]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). 抱歉,我无法显示实际视图(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? 您的booleanToVisibilityConverter是否返回Visibility.Collapsed或.Hidden为False? It should return Collapsed in order for the space to be reclaimed. 它应该返回Collapsed以便回收空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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