Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combo Box [EVENTBINDING] Warning!!! #219

Open
DheerajSaravagi opened this issue Dec 23, 2015 · 4 comments
Open

Combo Box [EVENTBINDING] Warning!!! #219

DheerajSaravagi opened this issue Dec 23, 2015 · 4 comments

Comments

@DheerajSaravagi
Copy link

while using combo box selection change event its working fine but showing warning in console

[EVENTBINDING]: Could not find command target for event 'SelectionChanged'

below code is for reference

---------------------------<xaml code goes here >--------------------------

<ComboBox ItemsSource="{Binding Path=DropdownValues}"
                                       SelectedItem="{Binding Path=SelectedValue, Mode=TwoWay}"
                                       MinWidth="300"
                                       Height="30"
                                       Margin="5,0,0,0"
                                       DisplayMemberPath="Description"
                                       SelectedValuePath="Description"
                                       VerticalAlignment="Center"  
                                       IsDropDownOpen="{Binding Path=drpclose, Mode=TwoWay}"
                                       SelectionChanged ="{EventBinding Command={Binding DataContext.cmdDropdownValues_SelectedItemChanged, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}}}" CommandParameter="{Binding}"                                       
                                       Visibility="{Binding  Path=ShowDropDown, Converter={StaticResource BooleanToVisibilityConverter}}"  />


----------------------------------<typescript code>------------------------------------
cmdDropdownValues_SelectedItemChanged: Fayde.MVVM.RelayCommand;

this.cmdDropdownValues_SelectedItemChanged = new Fayde.MVVM.RelayCommand(parm => this.DropdownValues_SelectedItemChanged(parm));


DropdownValues_SelectedItemChanged(e: any): void {

    }
@BSick7
Copy link
Member

BSick7 commented Dec 23, 2015

It's warning you because your EventBinding is most likely incorrect.
I would recommend against using SelectionChanged altogether.
Since you already have a two-way binding for the selection, you could watch the change in your view model.

class VendorSearchViewModel ... {
...
  OnPropertyChanged(propertyName: string) {
    super.OnPropertyChanged(propertyName);
    if (propertyName === "SelectedValue") {
      //changed code
    }
  }
}

@BSick7
Copy link
Member

BSick7 commented Dec 23, 2015

If you are still sold on using EventBinding, try changing to this:

(Remove the RelayCommand)

OnSelectedValueChanged(e: Fayde.IEventBindingArgs<Fayde.Controls.Primitives.SelectionChangedEventArgs >) {
  var value = e.args.NewValues[0];
  if (!value)
    return;

  var ParentObject = this.Criteria.GetValueAt(0);
  ParentObject.SelectedValue = value;
  if (value.Description == "Section" || value.Description == "AnswerStatus")
    ParentObject.Criteria = value.Key;
  else
    ParentObject.Criteria = value.Description;
}
SelectionChanged="{EventBinding Command={Binding DataContext.OnSelectedValueChanged, RelativeSource={RelativeSource ItemsControlParent}}, CommandParameter="{Binding}}"

@DheerajSaravagi
Copy link
Author

We have used EventBinding so many places for many controls. This issue occurs only when we create new MVVM class object and assign to ContentControl for Page Navigation purpose. On page initialization stage it shows warning message in console.
If we use only SelectionChanged={EventBinding functionName} then also it show warning message in above scenario. However this event and page functionality works fine once page is loaded.

@BSick7
Copy link
Member

BSick7 commented Dec 23, 2015

It is possible that your DataContext may be swapping and causing the SelectedValue to change. During the DataContext swap, the EventBinding won't be able to find the callback as it is reporting.
I wanted to warn the developer rather than have the developer confused why the event binding wasn't working.

This is why I recommend against using SelectionChanged. I built it to be compatible, but in your case, there is no reason to use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants