ScrollViewer实际高度返回不正确的值?

时间:2012-05-16 22:22:02

标签: wpf xaml drawing scrollview

无论我做什么,我都不能将行范围设置为滚动视图的底部:(

enter image description here

<Grid>
    <DockPanel
        HorizontalAlignment="Stretch"
        Name="dock"
        VerticalAlignment="Stretch"
        LastChildFill="True"
        Focusable="True">
        <Menu
            Name="menuBar"
            HorizontalContentAlignment="Stretch"
            BorderThickness="0,0,0,1"
            BorderBrush="Silver"
            VerticalAlignment="Top"
            DockPanel.Dock="Top">
            <MenuItem
                Header="File" />
            <MenuItem
                Header="Options">
                <MenuItem
                    Header="Personal Info" />
            </MenuItem>
            <MenuItem
                Header="View" />
            <MenuItem
                Header="About" />
        </Menu>
        <TextBox
            Name="txtInput"
            DockPanel.Dock="Bottom"
            Height="23"
            SpellCheck.IsEnabled="True"
            VerticalAlignment="Bottom"
            BorderThickness="1,2,1,1"
            KeyDown="txtInput_KeyDown"
            TabIndex="1" />
        <ListBox
            Name="lstUsers"
            ItemsSource="{Binding}"
            DockPanel.Dock="Right"
            Width="160"
            BorderThickness="2,0,0,0"
            BorderBrush="LightGray" />
        <ScrollViewer
            Name="lstMessagesScroll"
            VerticalScrollBarVisibility="Auto">
            <ItemsControl
                Name="lstMessages"
                ItemsSource="{Binding}"
                VerticalAlignment="Bottom" />
        </ScrollViewer>
    </DockPanel>
    <Line
        StrokeThickness="0.5"
        X1="116"
        X2="116"
        Y1="23"
        Stroke="Gainsboro"
        Y2="{Binding ElementName=lstMessagesScroll, Path=ActualHeight}" />
</Grid>

任何提示?

2 个答案:

答案 0 :(得分:0)

它工作正常 - 只是您没有将菜单带入帐户。

答案 1 :(得分:0)

在玩你的XAML时,我发现如果你将Height绑定到同一个元素并将Y1设置为0,它将按照我认为你期望的方式行事。

<Line
    StrokeThickness="0.5" 
    X1="116" 
    X2="116" 
    Y1="0"
    Stroke="Gainsboro"     
    Y2="{Binding ElementName=lstMessagesScroll, Path=ActualHeight }"
    Height="{Binding ElementName=lstMessagesScroll, Path=ActualHeight }" />