WPF ScrollViewer大小 [英] WPF ScrollViewer Size

查看:398
本文介绍了WPF ScrollViewer大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个 scrollviewer 大小本身的问题。



我有以下xaml:



I'm having an issue with having a scrollviewer size itself.

I have the following xaml:

<Grid >
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <Grid Grid.Row="0" Grid.Column="0">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <!-- record number panel -->
        <Border x:Name="borderLeftColHeader" Grid.Row="0" >
            <!-- content stuff here -->
        </Border>

        <!-- QUESTIONS LIST -->
        <Grid Grid.Row="1" x:Name="gridScrollView" Margin="0,0,5,0" >
            <ScrollViewer x:Name="svQuestions" VerticalScrollBarVisibility="Auto" 

                          Height="{Binding Path=ActualHeight, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Grid}}" >
				
                <!-- this grid is filled in code-behind when the 
                parent user control is instantiated - can have 1-n 
                children -->
                <Grid x:Name="gridQuestions" />
				
            </ScrollViewer>
        </Grid>

        <!-- QUESTION BUTTONS ROW 1 -->
        <Grid Grid.Row="2" Margin="0,0,5,0" >
            <!-- content stuff here -->
        </Grid>
        <!-- QUESTION BUTTONS ROW 2 -->
        <Grid Grid.Row="3" Margin="0,5,0,0">
            <!-- content stuff here -->
        </Grid>
    </Grid>
</Grid>





我的问题是,如果我专门设置了滚动查看器的高度,它会按预期显示。



如果我使用上面指出的绑定( Path = ActualHeight,RelativeSource = {RelativeSource Mode = FindAncestor,AncestorType = Grid} ),它使用其父网格的 ActualHeight 始终为0



我也尝试绑定到网格的元素名称(使用相同的 Path = ActualHeight )。



我还尝试将 SizeChanged UpdatedLayout 事件处理程序添加到父用户控件和所有相关元素,所以我可以在调试器中检查父网格的 ActualHeight gridScrollView ),并且它总是0.



我没有想法。我需要做些什么才能确保将 gridScrollView.ActualHeight 设置为有用的东西,最好是在实例化用户控件时?



My problem is that if I specifically set the height of the scrollviewer, it displays as expected.

If I used the binding indicated above (Path=ActualHeight, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Grid}), it uses the ActualHeight of its parent grid which is always 0.

I also tried binding to the grid's element name (using the same Path=ActualHeight).

I also tried adding SizeChanged and UpdatedLayout event handlers to the parent user control and all related elements so I could inspect the ActualHeight of the parent grid (gridScrollView) in the debugger, and it's always 0.

I'm out of ideas. What do I need to do to ensure that the gridScrollView.ActualHeight gets set to something useful, preferably when the user control gets instantiated?

推荐答案

没关系。我发现了这个问题。包含此混乱的网格有一组不需要的行定义(我使用的行设置为Auto。
Never mind. I found the problem. The grid containing this mess had a set of row definitions that weren't needed (and the row I was using was set to "Auto".


这篇关于WPF ScrollViewer大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆