question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Combobox : EventTriggerBehavior SelectionChanged is triggered before the SelectedItem

See original GitHub issue

Hello,

In a mvvm combobox, the EventTriggerBehavior SelectionChanged is triggered before the SelectedItem

<ComboBox x:Name="cmbMainLang"
      assists:ComboBoxAssist.Label="{Binding Hint}"
      PlaceholderText="{Binding Hint}"
      MaxDropDownHeight="200"
      Margin="0 40 0 0"
      DataContext="{Binding UILanguagesComboBox}"
      Items="{Binding Items}"
      SelectedItem="{Binding Selected}">
    <Interaction.Behaviors>
        <EventTriggerBehavior EventName="SelectionChanged">
          <InvokeCommandAction Command="{Binding SelectCommand}"/>
        </EventTriggerBehavior>
    </Interaction.Behaviors>
</ComboBox>

This lead to an unsynchonized combobox value & command

Thanks

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
Whiletru3commented, Feb 23, 2022

Of course 😃 thanks a lot for the confirmation

1reaction
wieslawsoltescommented, Feb 23, 2022

@wieslawsoltes : Hello, we found a workaround using ValueChangedTriggerBehavior.

<ComboBox x:Name="cmbMainLang"
                              assists:ComboBoxAssist.Label="{Binding Hint}"
                              PlaceholderText="{Binding Hint}"
                              MaxDropDownHeight="200"
                              Margin="0 40 0 0"
                              DataContext="{Binding UILanguagesComboBox}"
                              Items="{Binding Items}"
                              SelectedItem="{Binding Selected}">
  <Interaction.Behaviors>
	<ValueChangedTriggerBehavior Binding="{Binding Selected}">
               <InvokeCommandAction Command="{Binding SelectCommand}"/>
         </ValueChangedTriggerBehavior>
    </Interaction.Behaviors>
</ComboBox>

Do you agree that it is a good workaround ?

I would not call it workaround, more like correct solution to what Avalonia framework currently does.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ComboBox SelectedItem binding updates after ...
Since the name of the EventTriggerBehavior is SelectionChanged, the event should be triggered after the selection has been changed (or has been ...
Read more >
Combobox selectionchanged event triggers without even ...
After that everything works perfectly, I wonder what triggers the ComboBox SelectionChanged Event before even loading the window.
Read more >
How to trigger SelectionChanged event when ComboBox ...
I want to open that different window again and again by selecting the last item it does not matter if I select the...
Read more >
How to get SelectedItem in the ComboBox?
I've another Custom Control, Combo which is an extended ComboBox, and it raises SelectionChanged whenever I change selection.
Read more >
How can I prevent SelectionChanged event for a ...
One strategy is to structure your code so that it doesn't matter. For example let's say changing the combo box selection populates a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found