0

Combobox binding breaks after button click wpf mvvm. I have used interaction trigger to bind combobox selection changed to an ICommand.

 <ComboBox  IsEditable="True" Text="Please Select" IsReadOnly="True" ItemsSource="{Binding Items}" SelectedItem="{Binding SelectedItem}">
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="SelectionChanged">
                            <i:InvokeCommandAction Command="{Binding SelectionChangedCommand}" />
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </ComboBox>
 <Button Content="Save"  Command="{Binding SaveCommand}" />

Binding works fine till save button's command is fired. Once save command of button is fired, combobox selectionchange command breaks

Edit: Items is a list of string like below

           "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", 
           "B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8", 
           "C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", 
           "D1", "D2", "D3", "D4", "D5", "D6", "D7", "D8"

Selected item is displayed in a readonly textbox and when the alphabet changes, SelectionChangedCommand binding breaks (SelectedItem is no longer updated but, on clicking save, its updated).

Note that Combobox's SelectedItem is bound to below property of ViewModel.

 private string _SelectedItem;
            public string SelectedItem
            {
                get
                {
                    return _SelectedItem;
                }
                set
                {
                    if (_SelectedItem!= value)
                    {
                        _SelectedItem= value;
                        RaisePropertyChanged(() => SelectedItem);
                    }
                }
            }
13
  • Is SelectionChangedCommand from Telerik? Commented Dec 27, 2013 at 19:59
  • 1
    Its hard to give any answer with just the details provided here. Can you explain what you mean by "breaks"? Do you mean the SelectedItem no longer gets updated? The SelectionChangedCommand no longer executes? The CanExecute no longer returns true? It could be any number of things, I don't think we can tell with the limited information provided. And can you share what your SaveCommand does to the SelectedItem? (doesn't have to be the exact calculation code, but does it change the SelectedItem value? do anything else related to the SelectChangedCommand or its CanExecute? Commented Dec 27, 2013 at 20:18
  • 1
    @user2951819, well, the only thing i can suggest is to run your application in the debugger. Monitor (with the help of a breakpoint), whether the SelectionChangedCommand CanExecute/Execute methods are called and what they are doing. If they are not called, look in the debugger output window for some information regarding failed bindings or triggers. Commented Dec 27, 2013 at 20:18
  • 1
    @user2951819, set a breakpoint on the setter of that property and debug it! Commented Dec 27, 2013 at 21:24
  • 2
    @user2951819, glad to hear you solved the issue :) Commented Dec 28, 2013 at 22:50

1 Answer 1

0

I'm wondering why you want to get both, the notification via "SelectedItem" AND the InvokeCommandAction. In the setter of your SeletedItem you can do what you want and you hold the new selection in your hand.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.