ScrollViewer没有正常显示?

时间:2009-07-20 16:12:21

标签: c# wpf scrollviewer

有谁知道我的代码出了什么问题:

<Border Background="AliceBlue" BorderThickness="2">
    <Grid Name="MainGrid" Background="DarkGray" >
        <Grid.RowDefinitions>
            <RowDefinition Height="0.02*"/>
            <RowDefinition Height="0.07*"/>
            <RowDefinition Height="0.63*"/>
            <RowDefinition Height="0.05*"/>
            <RowDefinition Height="0.05*"/>
        </Grid.RowDefinitions>   

        [...SNIP...]

           <StackPanel Grid.Row="2">
            <Expander Header="Filteroptionen" Foreground="WhiteSmoke" FontWeight="Bold">
                <Border Margin="18,10,18,10" Name="border1" CornerRadius="10,10,10,10" Background="Gray" >
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition></ColumnDefinition>
                            <ColumnDefinition></ColumnDefinition>
                            <ColumnDefinition></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <StackPanel Margin="15,5,5,5" Grid.Column="0">
                            <RadioButton FontWeight="Normal" Foreground="White" Height="19" Name="radtest1">test1</RadioButton>
                            <RadioButton FontWeight="Normal" Foreground="White" Height="19" Name="radtest2">test2</RadioButton>
                            <RadioButton FontWeight="Normal" Foreground="White" Height="19" Name="radtest3">test3</RadioButton>
                        </StackPanel>
                            <StackPanel Margin="15,5,5,5" Grid.Column="1">
                                <my:DatePicker HorizontalAlignment="Left" Height="25" Name="datePicker1" Width="115" Text="Von" />
                                <my:DatePicker HorizontalAlignment="Left" Height="25" Name="datePicker2" Width="115" Text="Bis" IsEnabled="True" />
                            </StackPanel>
                            <StackPanel Margin="15,5,5,5" Grid.Column="2">
                                <WrapPanel>
                                    <Label FontWeight="Normal" Foreground="White" >Number</Label>
                                    <TextBox FontWeight="Normal" Width="193"></TextBox>
                                </WrapPanel>
                                <WrapPanel>
                                    <Label FontWeight="Normal" Foreground="White" >Name</Label>
                                    <TextBox FontWeight="Normal" Width="250"></TextBox>
                                </WrapPanel>

                            </StackPanel>

                        </Grid>
                </Border>
            </Expander>
                    <Border Margin="18,10,18,10" CornerRadius="10,10,10,10" Background="Gray" >
                        <my:DataGrid Margin="10,10,10,10" ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="auto" ItemsSource="{Binding}" Name="mainDataGrid" xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit" />
                </Border>
            </StackPanel>

我在这里添加了一个显示问题的图像(我的滚动条没有正确显示,我认为它被网格切割):
Picture

非常感谢您的帮助!

干杯

2 个答案:

答案 0 :(得分:2)

包含面板的高度不受约束。发生的事情是你的包含面板(包含DataGrid的StackPanel)正在增长,因此DataGrid认为它不需要滚动。

尝试在StackPanel上设置高度值(如窗口的高度或类似值)。然后滚动条应该出现并起作用。

答案 1 :(得分:0)

或者,如果您的容器没有固定的高度,请在ScrollViewer上设置MaxHeight。