垂直和水平ScrollBars无法正常工作 - WPF

时间:2015-07-23 16:28:12

标签: c# wpf

我有以下代码:

<DockPanel>
        <Grid>
            <Grid.ColumnDefinitions>
                <!--This will make any control in this column of grid take 1/10 of total width-->
                <ColumnDefinition Width="1*" />
                <!--This will make any control in this column of grid take 4/10 of total width-->
                <ColumnDefinition Width="4*" />
                <!--This will make any control in this column of grid take 4/10 of total width-->
                <ColumnDefinition Width="4*" />
                <!--This will make any control in this column of grid take 1/10 of total width-->
                <ColumnDefinition Width="1*" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition />
            </Grid.RowDefinitions>
            <Border BorderBrush="Black" BorderThickness="1" Grid.Row="0" Grid.Column="0">
                <StackPanel>
                    <Image Source="/SAMPLE;component/Images/1_Left.png"/>
                    <Image Source="/SAMPLE;component/Images/2_Left.png"/>
                    <Image Source="/SAMPLE;component/Images/3_Left.png"/>
                    <Image Source="/SAMPLE;component/Images/4_Left.png"/>
                </StackPanel>
            </Border>
            <ScrollViewer Grid.Row="0" Grid.Column="1">
                <Canvas Name="Canvas1">
                    <Image Name="LeftImage"/>
                    <Image Name="LeftIcon"/>
                </Canvas>
            </ScrollViewer>
            <ScrollViewer Grid.Row="0" Grid.Column="2">
                <Canvas Name="Canvas2">
                    <Image Name="RightImage"/>
                    <Image Name="RightIcon"/>
                </Canvas>
            </ScrollViewer>
            <Border BorderBrush="Black" BorderThickness="1" Grid.Row="0" Grid.Column="3">
                <StackPanel>
                    <Image Source="/SAMPLE;component/Images/5_Right.png"/>
                    <Image Source="/SAMPLE;component/Images/6_Right.png"/>
                    <Image Source="/SAMPLE;component/Images/7_Right.png"/>
                    <Image Source="/SAMPLE;component/Images/8_Right.png"/>
                </StackPanel>
            </Border>
        </Grid>
    </DockPanel>

即使“LeftImage”和“RightImage”具有更多宽度和高度,滚动条也不起作用。我无法滚动查看完整的图像。有什么帮助吗?

由于

1 个答案:

答案 0 :(得分:0)

网格不支持滚动功能。如果要滚动某些内容,则需要ScrollViewer控制。因此,请将您的网格放在ScrollViewer DockPanel

<ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible"> //Your grid </ScrollViewer>
session_start();
if(isset($_POST['viewrecord'])){
    $sup_code = $_POST['vhidden'];
}
$_SESSION["sup_code"] = $sup_code;