水平ItemControl项的宽度不超过itemControl的宽度

时间:2018-12-28 15:59:37

标签: xaml itemscontrol

我不知道如何使itemControl的项目激活项目控件的水平滚动条。我的情况是只有一项时。当itemSource中存在多个项目时,将显示一个滚动条。但是项目模板的构建方式是,每个项目都足够长,可以延伸到超过父对象宽度的宽度。我假设我将需要使用Pixel作为滚动单元,但这并没有什么不同。

<ItemsControl Grid.Row="1" ItemsSource="{Binding LAndUDataPoints[0].Models, Mode=OneWay}" HorizontalContentAlignment="Stretch" ItemTemplate="{StaticResource LAndUItemTemplate}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate >
            <VirtualizingStackPanel Orientation="Horizontal" ScrollUnit="Pixel" />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
</ItemsControl>

enter image description here

1 个答案:

答案 0 :(得分:2)

ItemsControl(和ListBox)进行智能滚动(滚动时跳转到每个项目),但是有了一个项目,它只会停留在第一个项目的开头(不需要滚动条)因为在可见窗口之外没有第二个项目。

如果您想要更平滑的滚动并保持虚拟化,则应切换为使用TreeView,例如:

<TreeView Grid.Row="1" ItemsSource="{Binding LAndUDataPoints[0].Models, Mode=OneWay}" HorizontalContentAlignment="Stretch" ItemTemplate="{StaticResource LAndUItemTemplate}">
    <TreeView .ItemsPanel>
        <ItemsPanelTemplate >
            <VirtualizingStackPanel Orientation="Horizontal" />
        </ItemsPanelTemplate>
    </TreeView .ItemsPanel>
</TreeView >

在这种情况下,ScrollUnit="Pixel"上不需要VirtualizingStackPanel

相关问题