滚动条即使放在滚动查看器中也不会显示在stackpanel中

时间:2017-05-14 15:53:06

标签: c# wpf xaml mvvm stackpanel

我正在尝试将一个滚动查看器添加到stackpanels - “gradpaneldesc”,“undergrapaneldesc”和“certficatedesc”,它们分别在另一个父stackpanel-“mainpanel”中,但我无法实现这一点,因为它可能显示我的scrollviewer但是没有实际的滚动条,没有意识到错误在哪里。任何帮助将受到高度赞赏。

XAML

.first

CS

<UserControl x:Class="ISTE.Views.CoursesView"XAML
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:ISTE.Views"
             mc:Ignorable="d" 
             d:DesignHeight="600" d:DesignWidth="1300">
    <Grid>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="400"/>
            <ColumnDefinition Width="400"/>
            <ColumnDefinition Width="400"/>
        </Grid.ColumnDefinitions>
        <Image Source="/Images/degree.jpg"
                         Stretch="Fill"
                         Height="250"

                Grid.ColumnSpan="3"/>

        <StackPanel x:Name="mainpanel1" Grid.Column="0">
            <Button x:Name="Graduate" IsDefault="True" Click="Graduate_Click"   >
                <Button.Background>
                    <LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
                        <GradientStop Color="#FF235DF0" Offset="0"/>
                        <GradientStop Color="#FFE7EBF5" Offset="1"/>
                        <GradientStop Color="#FF9EB6F3" Offset="0.632"/>
                    </LinearGradientBrush>
                </Button.Background> Graduate
            </Button>
            <StackPanel x:Name="gradpanel" Height="200px"></StackPanel>
            <Border x:Name="myBorder2">
                <ScrollViewer>
                    <StackPanel x:Name="gradpaneldesc" Height="200px"></StackPanel>
                    </ScrollViewer>
            </Border>


        </StackPanel>
        <StackPanel x:Name="mainpanel2" Grid.Column="1">
            <Button x:Name="UnderGraduate" IsDefault="True" Click="UnderGraduate_Click"   >
                <Button.Background>
                    <LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
                        <GradientStop Color="#FF235DF0" Offset="0"/>
                        <GradientStop Color="#FFE7EBF5" Offset="1"/>
                        <GradientStop Color="#FF9EB6F3" Offset="0.632"/>
                    </LinearGradientBrush>
                </Button.Background> Undergraduate</Button>
            <StackPanel x:Name="undergradpanel" Height="200px"></StackPanel>
            <Border  x:Name="myBorder1">
                <ScrollViewer>
                    <StackPanel x:Name="undergradpaneldesc" Height="200px"></StackPanel>
                    </ScrollViewer>
            </Border>

        </StackPanel>
        <StackPanel Grid.Column="2">
            <Button x:Name="Certifications" IsDefault="True"  Click="Certifications_Click"    >
                <Button.Background>
                    <LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
                        <GradientStop Color="#FF235DF0" Offset="0"/>
                        <GradientStop Color="#FFE7EBF5" Offset="1"/>
                        <GradientStop Color="#FF9EB6F3" Offset="0.632"/>
                    </LinearGradientBrush>
                </Button.Background> Certifications</Button>
            <StackPanel x:Name="certpanel" Height="200px"></StackPanel>
            <Border  x:Name="myBorder3">
                <ScrollViewer>
                    <StackPanel x:Name="certificatedesc" Height="200px"></StackPanel>
                    </ScrollViewer>
            </Border>

        </StackPanel>

    </Grid>

1 个答案:

答案 0 :(得分:0)

您需要指定(nil) (nil) 0xfe72b0 而不是ScrollViewer的高度,否则StackPanel不会超出StackPanel和滚动条的范围不会显示。

ScrollViewer