Home > Net >  ListBox always scrolls to item with open ComboBox
ListBox always scrolls to item with open ComboBox

Time:12-18

I created a ListBox with a custom Dictionary that contains a ListBoxItem Style, the custom Items contain two ComboBoxes. But when i click the ComboBox of an item which is not on top of the list the list automatically scrolls so the item with the open combobox is on top of the list. It looks really weird, so id like to make it stop.

I already changed the ListBox to a ListView and changed the Itemtemplate to ListBoxItem but it didnt changed anything.

i would be happy about any advice thanks.

CodePudding user response:

You can overwrite this "scrolling-behaviour" with a custom style and an event-setter for the 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;
}
  • Related