获取Windows Phone中ScrollViewer的高度

时间:2014-06-29 17:34:51

标签: windows-phone-8.1 win-universal-app

我在Windows Phone应用程序(通用应用程序)中遇到有关ScrollViewer的问题。

我有一个像以下一样的ScrollViewer:

            <ScrollViewer x:Name="myScrollViewer" Grid.Row="1">
            <StackPanel>

                <TextBlock x:Name="myText"
                           Margin="12"
                           FontSize="30"
                           Text="Lorem Ipsum is simply dummy text of the printing and typesetting industry."
                           TextWrapping="Wrap"
                           />        
                <Rectangle Height="140"
                           Width="400"
                           Fill="Blue"
                           Margin="12"
                           />
                <Rectangle Height="140"
                           Width="400"
                           Fill="Red"
                           Margin="12"
                           />                                        
            </StackPanel>
        </ScrollViewer>

现在我正试图获得此ScrollViewer的高度。在后面的代码中(在构造函数内部),我尝试过:

double d = myScrollViewer.ActualHeight;

double d = myScrollViewer.ScrollableHeight;

double d = myScrollViewer.Height;

我还尝试了其他高度相关的方法来获得ScrollViewer的高度。但在每种情况下,我在d中得到NULL或0。有什么办法可以返回ScrollViewer的实际高度或工作高度吗?

1 个答案:

答案 0 :(得分:1)

你应该能够在Page的Loaded事件之后获得任何框架元素的ActualHeight。 ActualHeight和ActualWidth不是在构造函数时设置的,也不是在动​​态计算/测量控件等之前设置的。