无法在窗口的Frame元素内部的WPF子页面中查看滚动条

时间:2014-11-10 08:36:25

标签: c# wpf wpf-controls wpfdatagrid wpf-4.0

在我现有的应用程序中,我使用了导航。 为此,我在main window内加载了frame element个不同的页面。 这里,当页面中的控件数量增加时;我想在页面中添加scroll bar。但目前它出现在窗口中。另外,在我当前的代码中,SplitGrid中有3列 - 一个网格。 我希望第一列为25%,第三列为可用屏幕区域的75%宽度。这可能吗?

父窗口:

    <Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" ></RowDefinition>
    </Grid.RowDefinitions>
    <StackPanel Orientation="Vertical" HorizontalAlignment="Center">
        <TextBlock FontSize="24" HorizontalAlignment="Center" Text="Ribbon - (Main Menu + Sub Menu)" FontWeight="Bold"/>
        <Button Content="Test Button" Click="Button_Click" Width="100" Height="50" HorizontalContentAlignment="Center" VerticalAlignment="Center" />
    </StackPanel>

    <ScrollViewer VerticalScrollBarVisibility="Auto"
                                HorizontalScrollBarVisibility="Auto"
                                Grid.Row="1">
        <Grid Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" ></RowDefinition>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid Name="SplitGrid">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" MinWidth="350" ></ColumnDefinition>
                    <ColumnDefinition Width="Auto"></ColumnDefinition>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <Border BorderBrush="#DEB887" BorderThickness="2" CornerRadius="10" Grid.Column="0" HorizontalAlignment="Stretch">
                    <Border.Background>
                        <LinearGradientBrush EndPoint="0.5,0.9" StartPoint="0.5,0">
                            <GradientStop Color="#306EFF" Offset="0.9" />
                            <GradientStop Color="#BDEDFF" />
                        </LinearGradientBrush>
                    </Border.Background>
                    <StackPanel Orientation="Vertical">
                        <Border BorderThickness="2" CornerRadius="8"  Margin="5,15,5,10" x:Name="InnerBorder">
                            <Border.Background>
                                <LinearGradientBrush EndPoint="0.5,0.9" StartPoint="0.5,0">
                                    <GradientStop Color="#F0FFFF" Offset="0.9" />
                                    <GradientStop Color="#EBF4FA" />
                                </LinearGradientBrush>
                            </Border.Background>
                            <ScrollViewer VerticalScrollBarVisibility="Auto" >
                                <StackPanel Orientation="Vertical" Margin="0,0,0,10" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                                    <Frame NavigationUIVisibility="Automatic" Name="frmContent" Source="MainPage.xaml" />
                                </StackPanel>
                            </ScrollViewer>
                        </Border>
                    </StackPanel>
                </Border>
                <GridSplitter Grid.Column="1" Name="grdSplitter" Background="#3976FF" HorizontalAlignment="Center" VerticalAlignment="Stretch" ShowsPreview="True" Visibility="Visible" Width="5" />
                <StackPanel Background="Blue" Grid.Column="2"></StackPanel>
            </Grid>
        </Grid>
    </ScrollViewer>
</Grid>

的MainPage

<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
    <WrapPanel MinWidth="150" Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ScrollViewer}}, Path=ActualWidth}" HorizontalAlignment="Stretch">
        <Button Width="200" Height="50" Content="Button 1"/>
        .....
        <Button Width="180" Height="50" Content="Button 20"/>
    </WrapPanel>
</ScrollViewer>

1 个答案:

答案 0 :(得分:0)

在ScrollViewer中更改VerticalScrollBarVisibility="Visible"