【问题标题】:ListBox always scrolls to item with open ComboBoxListBox 总是滚动到打开 ComboBox 的项目
【发布时间】:2022-01-19 08:12:22
【问题描述】:

我使用包含 ListBoxItem 样式的自定义字典创建了一个 ListBox,自定义项包含两个 ComboBox。但是,当我单击不在列表顶部的项目的组合框时,列表会自动滚动,因此打开组合框的项目位于列表顶部。 它看起来很奇怪,所以我想让它停下来。

我已经将 ListBox 更改为 ListView 并将 Itemtemplate 更改为 ListBoxItem 但它没有改变任何内容。

我会很高兴任何建议谢谢。

【问题讨论】:

    标签: c# wpf listbox listboxitem


    【解决方案1】:

    您可以使用自定义样式和RequestBringIntoView-event 的事件设置器覆盖此“滚动行为”:

    <ListView.ItemContainerStyle>
        <Style TargetType="{x:Type ListViewItem}">
             <EventSetter Event="RequestBringIntoView" Handler="MyListView_OnRequestBringIntoView"/>
        </Style>
    </ListView.ItemContainerStyle>
    
    
    private void MyListView_OnRequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
    {
        e.Handled = true;
    }
    

    【讨论】:

    • 非常感谢它完美地解决了
    猜你喜欢
    • 1970-01-01
    • 2021-12-22
    • 1970-01-01
    • 2021-01-23
    • 2021-01-31
    • 2013-07-19
    • 2011-04-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多