如何在滚动时始终显示组合框中的特定项目

How to always show specific item from combobox while scrolling

我有一个组合框,里面装满了复选框项目。
当我向下滚动时,我希望组合框的第一项始终可见。
它应该有点像本网站或其他网站上的导航栏。

提前致谢。

您可以修改控件模板,请参阅this post如何提取它。

下面是丑陋(但有效)的解决方案,用于在弹出窗口顶部查看当前选定的项目,您可以根据自己的喜好进行修改:

为此,您必须如前所述提取组合框控件模板,然后搜索

<Popup x:Name="PART_Popup"

并修改其

<Border x:Name="DropDownBorder"

通过像这样在 Grid 中添加:

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <ContentControl Content="{TemplateBinding SelectionBoxItem}" />

现在只需为更早的现有滚动查看器设置网格行:

        <ScrollViewer x:Name="DropDownScrollViewer" Grid.Row="1">

不要忘记在它之后关闭 Grid 属性:

</Grid>