垂直滚动时冻结控制

时间:2011-12-27 13:49:36

标签: wpf xaml scroll scrollviewer

我在ScrollViewer中有一些控件组。我需要其中一个控件在垂直滚动时冻结。我该怎么做?

1 个答案:

答案 0 :(得分:0)

通过一些创造性地使用ListView,您可以实现所需的效果。您可能还需要调整一些ListView模板以避免某些特定于ListView的行为。

    <ListView ScrollViewer.CanContentScroll="False">
        <ListView.View>
            <GridView>
                <GridViewColumn>
                    <GridViewColumn.HeaderTemplate>
                        <DataTemplate>
                            <!-- Header/Frozen content goes here -->
                            <!-- Using Border as example -->
                            <Border Width="1000" Height="40">
                                <Border.Background>
                                    <LinearGradientBrush>
                                        <GradientStop Offset="0" Color="Lime"/>
                                        <GradientStop Offset="1" Color="Black"/>
                                    </LinearGradientBrush>
                                </Border.Background>
                            </Border>
                        </DataTemplate>
                    </GridViewColumn.HeaderTemplate>
                </GridViewColumn>
            </GridView>
        </ListView.View>
        <ListViewItem>
            <ListViewItem.Style>
                <Style TargetType="{x:Type ListViewItem}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <!-- Other content goes here -->
                                <!-- Using Border as example -->
                                <Border Width="1000" Height="1000">
                                    <Border.Background>
                                        <LinearGradientBrush>
                                            <GradientStop Offset="0" Color="White"/>
                                            <GradientStop Offset="1" Color="Black"/>
                                        </LinearGradientBrush>
                                    </Border.Background>
                                </Border>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </ListViewItem.Style>
        </ListViewItem>
    </ListView>