ScrollViewer不滚动ItemsControl更改

时间:2016-09-05 08:29:44

标签: c# wpf telerik scrollviewer

当ScrollViewer中ItemsControl的ItemsSource发生更改时,我在模式对话框中遇到ScrollViewer问题而不改变滚动行为。

首次创建对话框时,ScrollViewer的滚动条的行为与内容的大小一致。将项添加到ObservableCollection时,ItemsControl绑定到内容更改,但ScrollViewer不会对更改做出反应并激活滚动条。

ObservableCollection中的几项:

enter image description here

更多项目添加到ObservableCollection:

enter image description here

重启应用程序后:

enter image description here

<Grid x:Name ="Maingrid">
    <Grid.Resources>
        <ResourceDictionary>
            <!--Style for RadButtons-->
            <Style TargetType="telerik:RadButton" x:Key="RadButtonStyle">
                <Setter Property="Margin" Value="10"/>
                <Setter Property="Width" Value="95"/>
                <Setter Property="Height" Value="Auto"/>
                <Setter Property="HorizontalContentAlignment" Value="Center" />
            </Style>
            <!--end of Style for RadButtons-->
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/PS.Common.Presentation;Component/Themes/Generic.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Grid.Resources>
    <Grid.RowDefinitions>
        <RowDefinition Height="25" />
        <RowDefinition Height="200" />
        <RowDefinition Height="45" />
    </Grid.RowDefinitions>
    <!--List-->
    <ScrollViewer x:Name="LeftScrollViewer" Grid.Row="1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">

        <ItemsControl ItemsSource="{Binding BaysAndSystems, NotifyOnSourceUpdated=True}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <CheckBox Grid.Column="0" IsChecked="{Binding Selected}" Content="{Binding Item.NameAndReference}" />
                    </Grid>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>

    </ScrollViewer>
    <!--Buttons-->
    <StackPanel Grid.Row="2" Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Center">
        <telerik:RadButton Content="{x:Static resx:Resources.Copy}"   Command="{Binding CopyCommand}"     
                               CommandParameter="{Binding}" Style="{StaticResource RadButtonStyle}" />
        <telerik:RadButton Content="{x:Static resx:Resources.Cancel}" Command="{Binding CopyCancledCommand}" 
                               CommandParameter="{Binding}" Style="{StaticResource RadButtonStyle}" />
    </StackPanel>

</Grid>

如何让ScrollViewer对更改后的内容做出反应?

2 个答案:

答案 0 :(得分:0)

ScrollViewer位于Grid.Row="1",其高度固定。将此网格的行高更改为*。它应该工作。您也可以为VerticalScrollBarVisibility尝试不同的值。

答案 1 :(得分:0)

您的问题是,即使您定义了200像素,您的滚动查看器的行也会增加其高度。将其设置为&#34; *&#34;并在MaxHeight="200"上设置属性Row - 这样就可以了。

 <Grid.RowDefinitions>
        <RowDefinition Height="25" />
        <RowDefinition Height="*" MaxHeight="200" />
        <RowDefinition Height="45" />
    </Grid.RowDefinitions>