【问题标题】:Horizontal ItemControl item's width to not exceed itemControl's width水平 ItemsControl 项目宽度不超过 itemsControl 宽度
【发布时间】:2018-12-28 15:59:36
【问题描述】:

我不知道如何让 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>

【问题讨论】:

    标签: xaml itemscontrol


    【解决方案1】:

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-09
      • 2012-02-05
      相关资源
      最近更新 更多