开发者

Can't get WPF ScrollViewer to work

I have a StackPanel and for some reason I can't get the content of the ScrollViewer on the very bottom to be scrollable, despite the fact that the internal height of the Frame clearly exceeds the bounds of the ScrollViewer. I previously had a Grid as the root container of the Window, but when I changed it to StackPanel the scrollbar no longer appears.

The only thing that seems to work is if I explicitly set the height of the ScrollViewer, but then it does not size with thw Window when it's resized.

Do I have to use a Grid?

Sorry if this is obvious; I'm relatively new to WPF.

Thanks in advance for any help!

<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         d:DesignWidth="566" Width="719" >

    <StackPanel VerticalAlignment="Str开发者_如何学运维etch"  >
        <Menu HorizontalAlignment="Stretch" Name="Menu1" VerticalAlignment="Stretch" Width="Auto">
            <MenuItem Header="_File" Name="MenuItem1">
                <MenuItem Header="_Print" Name="MenuItem2" />
            </MenuItem>
        </Menu>

        <Canvas x:Name="SearchCanvas"  Width="681" Height="55">
            <ComboBox Canvas.Left="6" Canvas.Top="0" Height="22" x:Name="cbLookupField" Width="302" Text="" SelectedIndex="0">
                <ComboBoxItem Content="Reference Name" />
                <ComboBoxItem Content="Matter" />
                <ComboBoxItem Content="Client Loan Number" />
            </ComboBox>
            <TextBox KeyDown="tbLookup_KeyDown" Canvas.Left="6" Canvas.Top="28" Height="23" x:Name="tbLookup" Width="302" />

            <Button Canvas.Left="314" Canvas.Top="27" Content="Search" Height="24" Name="btnSearch" Width="106" />

            <ListView MouseDoubleClick="lvSearchResults_MouseDoubleClick" 
                      ItemsSource="{Binding Tables[0]}"  
                      Canvas.Left="-8" Canvas.Top="57" Height="129" Name="lvSearchResults" Width="697" Visibility="Hidden">
                <ListView.View>
                    <GridView x:Name="gvResultsGridView"/>
                </ListView.View>
            </ListView>
        </Canvas>

        <ScrollViewer  x:Name="ScrollViewer1" VerticalScrollBarVisibility="Visible">
            <Frame Height="Auto" Source="Full Report.xaml" VerticalAlignment="Stretch" x:Name="Frame1" />
        </ScrollViewer>
    </StackPanel>
</Window>


The ScrollViewer in the bottom does not have a fixed height, and therefore because it's contained in a StackPanel, its height will be the height of the content, which in this case is the Frame height.

You can either set a fixed height for the ScrollViewer, or use a Grid instead of a StackPanel. In case you use a grid you should set a fixed height for the row in which the ScrollViewer will be located.

Hope it helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜